My program is the follow:
#/usr/bin/python # -*- coding: latin-1 -*- import os, sys from geopy.geocoders import Nominatim geolocator = Nominatim() location = geolocator.reverse("47, 17") cim = location.raw['address']['country'] #cim = "Magyarország" print(cim) f = open('out.txt','w') f.write(cim) f.closed The program writes the correct value (Magyarország) at line 12, but at line 14 there is error. ('ascii' codec can't encode character ... in position 10)
And it's interesting, because when I give the value of cim at line 10, both of writings work.
(I'm totally beginner at python)
cim = u"Magyarország"try plscim = "Magyarország"(nouprefix on the string).from io import opento get the Python 3 file I/O system, or encode your data explicitly withf.write(cim.encode('utf8')).