1

I want to parse text file.
Lines in file look like this:

#all.kdadmin.filter.showAllEntries;-alle anzeigen-;-show all-;-pokaż wszystko-;-mostrar todo-; –ყველას გამოჩენა–

After:

step_0 = my_string.split(';')
print(step_0)

i have error:

UnicodeEncodeError: 'ascii' codec can't encode character '\u017c' in position 67: ordinal not in range(128)

All founded answer all old i don't understood it realy.
Can someone write me some peace of code how can i displey this lines in console or write in to other file?

LubieCiastka
  • 143
  • 1
  • 3
  • 9
  • 1
    Your terminal seems to be configured to handle ASCII characters only. Change this to UTF-8 or switch to a more powerful terminal. It might also be that the terminal *does* support UTF-8, but Python somehow doesn't realise this; in that case try exporting the environment variable `PYTHONIOENCODING="UTF-8"` before launching Python. – lenz Nov 28 '18 at 12:44
  • 1
    If you're on Windows, [this post](https://stackoverflow.com/q/507123) might help, despite its age. – lenz Nov 28 '18 at 12:46
  • yes, i'm working in PowerShell, but this simple code return the same error: `new_days = open('new_path.txt' ,'w') new_days.write(my_string) new_days.close()` can it still be a problem with a shell? – LubieCiastka Nov 28 '18 at 14:00
  • 1
    When you open a file for writing, you can specify the output encoding, ie. `open('new_path.txt', 'w', encoding='utf8')`. If you omit the `encoding=` parameter, the default is the same codec that is used for printing to the terminal. – lenz Nov 28 '18 at 14:06
  • Thanks @lenz for information about problem on Windows and for help with `encoding='utf8'` It's working now. – LubieCiastka Nov 28 '18 at 15:18

0 Answers0