[python-win32] Quoting Blanks in Command Line
Tim Golden
tim.golden at viacom-outdoor.co.uk
Tue Jul 15 18:35:13 EDT 2003
Andreas Maurer>
> I've a little script which gets a list of files from
> the command line.
> myscript.py -f file1,file2,"file3 with blank"
> gives
> ['-f,'file1,file2,"file3','with','blanks"']
> and not
> ['-f,'file1,file2,"file3 with blanks"']
Simplest suggestion is to use:
myscript.py -f file1 file2 "file3 with blank"
which will give:
C:\temp>temp.py file1 file2 "file3 with space"
['file1', 'file2', 'file3 with space']
or, if you must:
C:\temp>python
Python 2.2.2 (#37, Oct 14 2002, 17:02:34) [MSC 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> argv = ['-f', 'file1,file2,"file3 with space"']
>>> [s.split (",") for s in argv]
[['-f'], ['file1', 'file2', '"file3 with space"']]
>>>
depending on what you're after.
TJG
________________________________________________________________________
This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________
More information about the Python-win32
mailing list