One step up from str.split()
timothy.grant at gmail.com
Tue Jul 15 04:14:39 CEST 2008
On Mon, Jul 14, 2008 at 6:33 PM, Joel Koltner <zapwireDASHgroups at yahoo.com>
> I normally use str.split() for simple splitting of command line arguments,
> I would like to support, e.g., long file names which-- under windows -- are
> typically provided as simple quoted string. E.g.,
> myapp --dosomething --loadthis "my file name.fil"
> ...and I'd like to get back a list wherein ListEntry="my file name.fil"
> but just running str.split() on the above string creates:
> >>> ListEntry='myapp --dosomething --loadthis "my file name.fil"'
> >>> ListEntry.split()
> ['myapp', '--dosomething', '--loadthis', '"my', 'file', 'name.fil"']
> Is there an easy way to provide just this one small additional feature
> (keeping quoted names as a single entry) rather than going to a full-blown
> command-line argument parsing tool? Even regular expressions seem like
> probably be overkill here? Or no?
I've found that anytime I have more than one option on the command line,
optparse is the way to go. It works very very well for every circumstance
I've been able to throw at it.
tjg. [Timothy Grant]
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-list