0

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?

Community
  • 1
  • 1
illuminatedtiger
  • 1,431
  • 3
  • 12
  • 8

2 Answers2

3

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

Ignacio Vazquez-Abrams
  • 740,318
  • 145
  • 1,296
  • 1,325
2
>>> import pipes
>>> pipes.quote("\&*!")
"'\\&*!'"
ghostdog74
  • 307,646
  • 55
  • 250
  • 337
  • +1 for the relatively unknown `pipes` module, even if it's uncertain whether the OP is working on a Unix/Linux system. – tzot Feb 22 '10 at 22:13