Iterating command switches from a data file - have a working solution but it seems inefficient
Peter Otten
__peter__ at web.de
Thu Apr 13 04:10:12 EDT 2006
Peter Hansen wrote:
> I think you could just use getopt or optparse, passing in each line
> after doing a simple .split() on it. The resulting handling of the
> arguments would be much simpler and cleaner than what you have.
>
> That won't work perfectly well if you can have quoted arguments with
> spaces in them, however, but the example above does not.
shlex.split() may help with the splitting, e. g.:
>>> shlex.split("alpha beta --gamma 'delta epsilon' zeta\\ eta\n")
['alpha', 'beta', '--gamma', 'delta epsilon', 'zeta eta']
Peter
More information about the Python-list
mailing list