making a valid file name...

Jerry jweida at gmail.com
Tue Oct 17 12:29:24 EDT 2006


I would suggest something like string.maketrans
http://docs.python.org/lib/node41.html.  I don't remember exactly how
it works, but I think it's something like

>>> invalid_chars = "abc"
>>> replace_chars = "123"
>>> char_map = string.maketrans(invalid_chars, replace_chars)
>>> filename = "abc123.txt"
>>> filename.translate(charmap)
'123123.txt'

--
Jerry




More information about the Python-list mailing list