Apr-17-2021, 04:06 PM
(Apr-17-2021, 03:13 PM)johnboy1974 Wrote:(Apr-17-2021, 11:48 AM)snippsat Wrote: Your previous Thread
There talk about using json and not text when get data from API.
So if want to write as text file or something else use always utf-8 encoding when read and write.
with open('out.txt', 'w', encoding='utf-8') as f_out: s = 'Diósgyőr' f_out.write(s) with open('out.txt', 'r', encoding='utf-8') as f: print(f.read())
Output:Diósgyőr
HI mate,
Nice one and indeed about that earlier post. I remember the json converting it magically and thought maybe I had to convert it back.
Many thanks for that!
Cheers,
J
Hi,
Interestingly, I'm getting a different error.
JSON returns '1a Divisió'
File is writing: 1a Divisió
I've tried using utf-16 for no reason but it complained about a BOM.
response = requests.request("GET", url, headers=headers) json_data = response.json() myData = json_data['response'] . . . f = open(strLeaguesFile, 'a', encoding='utf-8') f.write(strLeagueName)CHeers,
J