There is Python 3.7.2
There is a txt file in cp1251 encoding, in it is text in Russian.
I try to output it to the console, and it gives me: codecs.StreamReaderWriter object at 0x0135adb0
So, how to make the text displayed?
Code:
import codecs
with codecs.open (r "D: \ pythonw \ qwer1.txt", "r", encoding = "cp1251") as line:
print (line)
|
1 answer
codecs.open () does not return a string, but an open file handler, from which you can read lines:
import codecs with codecs.open(r"D:\pythonw\qwer1.txt", "r", encoding="cp1251") as fh: for line in fh: print(line) - Thanks, it helped, and you can link where to read about it in the documentation. - likeulife pm
- did not pay attention, thanks again) - likeulife
|