invalid = '<>:"/\|?* ' for char in invalid: filename = filename.replace(char, '') print filename