Python OS Path Safe String
import re
invalidFile = "File!name?.txt"
f = open(os.path.join("/tmp", re.sub('[^-a-zA-Z0-9_.() ]+', '', invalidFile))
Bewildered Buzzard
import re
invalidFile = "File!name?.txt"
f = open(os.path.join("/tmp", re.sub('[^-a-zA-Z0-9_.() ]+', '', invalidFile))