views:

222

answers:

2

Possible Duplicate:
How to escape os.system() calls in Python?

Is there a Python method of making filenames safe (ie. putting \ infront of spaces and escaping ( , ), symbols) programatically in Python?

+2  A: 

Spaces are already "safe" for Python in open(). As for os.system() and similar functions, use subprocess instead.

Ignacio Vazquez-Abrams
+1  A: 
>>> import pipes
>>> pipes.quote("\&*!")
"'\\&*!'"
ghostdog74
+1 for the relatively unknown `pipes` module, even if it's uncertain whether the OP is working on a Unix/Linux system.
ΤΖΩΤΖΙΟΥ