open file with whitespaces

Fredrik Lundh fredrik at pythonware.com
Fri May 19 10:55:16 EDT 2006


"mardif" wrote:

> Now, I MUST open this file with os.spawn(os.P_WAIT ...., because I must
> wait the user cancel the explorer window, ok?

note that backslashes in string literals have special meaning in Python; to make
sure a backslash in the string literal really ends up as a backslash in the resulting
string, you must either double each backslash, or use "raw" strings:

    program = r"c:\programmi\internet explorer\iexplorer.exe"
    file = r"c:\documents and settings\username\desktop\cicciobello.html"

also, getting the quoting/escaping right with os.exec/os.spawn is quite messy.  I
recommend using the subprocess module instead:

    import subprocess
    print subprocess.call([program, file])

</F> 






More information about the Python-list mailing list