Is it possible to take a string with accented characters, store it in a local file, read it from that file, and restore it to its original form?
I have been trying to encode the string using utf-8. The write() method only takes str arguments. The decode() method only takes bytes arguments. I can't write to the file unless I encode the data, but I can't restore it.
Here is the code I am trying to run:
unicode = "utf-8"
name = "Dončić"
with open("doncic", 'w') as file:
file.write(str(name.encode(unicode)))
with open("doncic", 'r', encoding='utf8') as file:
print(file.read())
I've been searching for an answer for hours, and none of the solutions I've found have included any file i/o.
This is my first post! Thank you for your help!