On Jan 31, 2:56 pm, "A.T.Hofkamp" <[EMAIL PROTECTED]> wrote: > On 2008-01-30, grflanagan <[EMAIL PROTECTED]> wrote: > > > > > On Jan 29, 5:39 pm, kj <[EMAIL PROTECTED]> wrote: > > For command line options I get a long way with this: > > > [code python] > > def _getargs(): > > allargs = sys.argv[1:] > > args = [] > > kwargs = {} > > key = None > > while allargs: > > arg = allargs.pop(0) > > if arg.startswith('--'): > > key, arg = arg.split('=', 1) > > key = key[2:] > > elif arg.startswith('-'): > > key = arg[1:] > > if not allargs or allargs[0].startswith('-'): > > allargs.insert(0, 'yes') > > continue > > if key is None: > > args.append(arg) > > else: > > kwargs[key] = arg > > key = None > > return args, kwargs > > > ARGS, KWARGS = _getargs() > > [/code] > > Have a look at getopt (old) or optparse (newer) packages in the Python library > instead. > > Sincerely, > Albert
Admittedly I haven't used either of them, but getopt and optparse have always looked like too much work to me. 90% of the time my '_getargs' does what I need, and when it's insufficient I go straight to a config file (ConfigParser or ConfigObj). Best Regards Gerard -- http://mail.python.org/mailman/listinfo/python-list