Python Forum
Right way to write string into UTF-8 file?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Right way to write string into UTF-8 file?
#6
Thanks much for the tip on open(…, encoding='utf-8')!

I've also learned that UltraEdit (famous Windows editor) encodes files in Latin1 while PyScripter (IDE) uses UTF-8, so the latter is a much better alternative when working with accented strings.

stuff = "Crème"
with open("cp1252.txt", 'w') as outFile:
	outFile.write(stuff)
with open("utf8.txt", mode='w',encoding='utf-8') as outFile:
	outFile.write(stuff)
Using open() without any additional option meant that I ended up with a mix of Latin1 and UTF-8, which prevented me from using GpsBabel to merge GPX files.

I am using Python 3(.7.0).

Thanks again.

--
Edit: UltraEdit seems to have been rewritten to use Unicode instead.
Reply


Messages In This Thread
RE: Right way to write string into UTF-8 file? - by Winfried - Aug-29-2018, 05:22 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020