L
L
Les Alterman2016-12-13 22:26:14
linux
Les Alterman, 2016-12-13 22:26:14

How to change US-ASCII encoding to UTF-8 in Python 3.x?

Good day! When I run the program from the console (Linux), I get the error Unicodeencodeerror ascii codec can't encode characters in position 0-7 . I started looking for the error. It turned out that when running the program from the console, the locale.getpreferredencoding() function gives out: US-ASCII
UTF-8 is needed for normal text decod, but there is no sys.setdefaultencoding('utf-8') function in Python 3.
Question: How to change the encoding?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
U
Ulyana Illiterate, 2016-12-15
@karulyana

# -*- coding: utf-8 -*-
just insert at the beginning of the program

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question