I want to create a sane/safe filename (i.e. somewhat readable, no \"strange\" characters, etc.) from some random Unicode string (mich might contain just anything).
(
More or less what has been mentioned here with regexp, but in reverse (replace any NOT listed):
>>> import re >>> filename = u"ad\nbla'{-+\)(ç1?" >>> re.sub(r'[^\w\d-]','_',filename) u'ad_bla__-_____1_'