So I'm trying to save some cipher text to a new text file that is named by the user, however when I run the code it displays this message:
Please enter the name you wish the file to be called: cipher
Traceback (most recent call last):
File "C:/Users/User/Documents/file figure.py", line 19, in <module>
f.write(cipher_text_write)
File "C:\Python34\lib\encodings\cp1252.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\x8e' in position 1: character maps to <undefined>
I managed to figure out that it is the actual message that I want to save that is causing the problem. Any help will be appreciated!
Here's my code:
cipher_text = " «²²µ ³¿ ´§³« ¯¹ µ´«²² "
filename = input("Please enter the name you wish the file to be called: ")
cipher_text_write = str(cipher_text)
cipher_filename = filename + ".txt"
f = open(cipher_filename,"w+")
f.write(cipher_text_write)
f.close()