How to read Unicode file as Unicode string in Python -


i have file encoded in unicode or utf-8 (i don't know which). when read file in python 3.4, resulting string interpreted ascii string. how convert unicode string u"text"?

the term "unicode" refers standard, not particular encoding. since files in computers binary, there exist different ways of encoding unicode data in binary files. 1 of them "utf-8".

you can consult https://docs.python.org/3/howto/unicode.html

an example taken document (in section "reading , writing unicode data")

with open('unicode.txt', encoding='utf-8') f:   line in f:     print(repr(line)) 

in python 3, unlike python2, unicode string constants not written "u".


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -