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?
#9
If there's no way around it, I can live with accents being human-unreadable, but I wonder why JSON turns them into eg \u00e7.

BTW, I learned that you can't simply dump tracks into a file like I did above: To have a clean file, you must first build a list, and a collection, and dump the collection:

with open(INPUTFILE, encoding='utf-8') as f:
    gj = geojson.load(f)

features = []
for track in gj['features']:
    features.append(track)

feature_collection = FeatureCollection(features)
with open('myfile.geojson', 'w') as f:
    dump(feature_collection, f, indent=2)
Reply


Messages In This Thread
RE: Right way to write string into UTF-8 file? - by Winfried - Aug-29-2018, 06:10 PM

Forum Jump:

User Panel Messages

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