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
--
http://mail.python.org/mailman/listinfo/python-list