Spaces in path name

David S davids at evertech.com.au
Fri Mar 14 20:15:47 EDT 2008


By mapping network drives in windows I can get past these issues with path 
names.

Thanks,
David

"Tim Golden" <mail at timgolden.me.uk> wrote in message 
news:mailman.1949.1205496184.9267.python-list at python.org...
> David S wrote:
>> Gets me further but still seems to be issue with space after 'Program' as 
>> code tries to run 'C:\Program'. Don't understand what is going on here...
>
> Slight apologies as I haven't followed this thread closely, but using the 
> Acrobat Reader executable, which is, I think, good enough for the
> purposes of illustration:
>
> <code>
> import os
> import subprocess
>
> filename = r"C:\Program Files\Adobe\Reader 8.0\Reader\AcroRd32.exe"
> doc = r"C:\Program Files\Adobe\Reader 8.0\Resource\ENUtxt.pdf"
>
> print os.path.isfile (filename)
>
> os.system (filename + " " + doc)
>
> os.system ('"%s" "%s"' % (filename, doc))
>
> subprocess.call ([filename, doc])
>
> </code>
>
> os.path.isfile succeeds
> os.system (filename) fails as your code does
> os.system ('"%s"' ...) fails even though both strings are requoted
> subprocess.call (filename) succeeds
>
> The latter, at least, is because the subprocess module
> has some special-case handling for exactly this situation
> on MS Windows, while os.system doesn't.
>
> Now, ultimately, I don't know if this really helps your
> exact situation but it least it should be clear what will
> and what won't work. Conclusion: use subprocess.call if
> you can.
>
> TJG 





More information about the Python-list mailing list