os.system and quoted strings

Duncan Booth duncan.booth at invalid.invalid
Wed Feb 28 05:28:29 EST 2007


"Dan Bishop" <danb_83 at yahoo.com> wrote:

> Windows system calls treat / and \ interchangeably, but the command
> prompt insists on backslashes.

No. Commands built-in to the command prompt and certain other programs 
(mostly but not exclusively from Microsoft) insist on backslashes. Most 
programs, especially those originating from the unixverse, will accept 
backslashes and forward slashes interchangeably from the command prompt. 
Even a lot of Microsoft's own programs are happy to accept backslashed 
command line arguments.

If in doubt just call os.path.normpath() on a path string before using it.
Also it is usually worth putting command line arguments inside " marks to 
avoid problems with spaces or other special characters in path names.



More information about the Python-list mailing list