Thank you for your reply.

I think I'll use PyWin32 if it's available on the user's system, and otherwise 
fall back to using subprocess.Popen, since I want my script to be 
cross-platform. os.startfile won't work for me because you can't pass arguments 
to the file being started. (When I first asked my question, I was thinking I 
might just need to pass a certain STARTUPINFO flag to subprocess.Popen, but it 
looks like that's not the solution.)

A few examples from the interactive interpreter should help to explain why I am 
doing the "\ \\ dance" (I used raw strings in these examples so that I wouldn't 
need to escape the backslashes):

>>> import shlex
>>> shlex.split(r'C:\Users\Timothy\Documents\Python\myscript.py')
['C:UsersTimothyDocumentsPythonmyscript.py']
>>> shlex.split(r'C:\\Users\\Timothy\\Documents\\Python\\myscript.py')
['C:\\Users\\Timothy\\Documents\\Python\\myscript.py']
>>> shlex.split(r'C:\Users\Timothy\Documents\Python\myscript.py', posix=False)
['C:\\Users\\Timothy\\Documents\\Python\\myscript.py']

The first example shows that single backslashes get removed. The second example 
shows that double backslashes are preserved intact. The third example shows 
that if posix=False, single backslashes are converted to double backslashes. 
None of these three behaviors are acceptable to correctly parse a Windows path, 
which is why I am doing what I am to work around the issue.

-- Timothy
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to