I have a string which contain some data I parse from the web, and make a file named after this data.
string = urllib.urlopen("http://example.com").read()
f = open(path + "/" + string + ".txt")
f.write("abcdefg")
f.close()
The problem is that it may include one of this characters: \ / * ? : " < > |
.
I'm using Windows, and it is forbidden to use those characters in a filename.
Also, string
is in Unicode formar which makes most of the solutions useless.
So, my question is: what is the most efficient / pythonic way to strip those characters? Thanks in advance!
Edit: the filename is in Unicode format not str!