On Mon, 16 Nov 2009 23:18:23 -0000, rantingrick <rantingr...@gmail.com> wrote:

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:\\echo.py C:\\New Folder\\text.txt'

inside my script i get the following result from sys.argv

['C:\\Python26\\Python.exe', 'C:\\echo.py', '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:\echo.py "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 consequences.

--
Rhodri James *-* Wildebeest Herder to the Masses
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to