[Tutor] Why is this not working? Seems like a whitespace issue

Alan Gauld alan.gauld at btinternet.com
Mon Feb 5 10:09:30 CET 2007


"Gizmo" <gizmo1 at gmail.com> wrote

>>>> import os
>>>> process=r"C:\Program Files\WinRAR\Rar.exe"
>>>> startDir = r"C:\to burn"
>>>> os.system(process+" x "+"C:\\to burn\\somemovie\\mymovie.rar"+"
> "+startDir)
>
> This doesnt work for me.. I get the error "  'C:\Program' is not 
> recognized

> whenever you have whitespaces in your path, ...enclose the
> whole path in double quotes; for example:

You got the right problem. The solution is to enclose your process
string in single quotes (or tripple quotes if you prefer!) That way 
your
double quotes will be passed through untouched.

It would make your code slightly easier to maintain if you were
more consistent in the approach though. In some places you use
raw strings in others double escaped strings. That could lead
to confusion later.

Just a thought,

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 




More information about the Tutor mailing list