Command line arguments??

Rhodri James rhodri at
Tue Nov 17 00:30:09 CET 2009

On Mon, 16 Nov 2009 23:18:23 -0000, rantingrick <rantingrick at>  

> I am currently having "fun" with command line arguments in a windows
> environment. If i get a path that has spaces anywhere in it my script
> gets the wrong arguments from sys.argv. You guy's probably know what i
> am talking about. Heres and example.
> 'C:\\Python26\\Python.exe C:\\ C:\\New Folder\\text.txt'
> inside my script i get the following result from sys.argv
> ['C:\\Python26\\Python.exe', 'C:\\', 'C:\\New', 'Folder\
> \text.txt']
> So i've got a few options
>   1. have people replace every space in all file paths system wide
> (sucks)
>   2. Create a custom parser, join the argv list, parse it...(maybe)
>   3. please tell me there is an option 3? (hopefully)

Quote the filenames or escape the spaces:

C:\Python26\Python.exe C:\ "C:\New Folder\text.txt"

We've been living with this pain ever since windowed GUIs encouraged users  
to put spaces in their file names (Apple, I'm looking at you!).   
Fundamentally, if people want the pretty they have to live with the  

Rhodri James *-* Wildebeest Herder to the Masses

More information about the Python-list mailing list