ANKUR AGGARWAL wrote:

> Hey- suppose we have a file name-"my file number"
> if we want to execute it into the terminal it would be like - my\ file\
> number
> 
> so wondering is there any one in the python that change the enter string
> into the terminal string one-
> like if user enter the file name with path- "my file number". i want to
> automatically convert it into "my\ file\ number"

If you want this to prepare an os.system() call you should instead use 
subprocess.call() with a list containing the command and a filename that is 
not escaped.

>>> import subprocess, os

Bad:

>>> os.system(r"ls -l my\ file\ number")
-rw-r--r-- 1 petto petto 0 2010-08-12 15:20 my file number
0

Good:

>>> subprocess.call(["ls", "-l", "my file number"])
-rw-r--r-- 1 petto petto 0 2010-08-12 15:20 my file number
0

Peter

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to