valid_chars = '-_.() %s%s' % (string.ascii_letters, string.digits)
valid_chars
filename = 'This Is a (valid) - filename%$&$ .txt'
"""""".join(c for c in filename if c in valid_chars)
Turn a string into a valid filename?