reading from file

Sydoruk Yaroslav swift at mirohost.net
Thu Jun 11 16:24:51 EDT 2009


Hello all,

In a text file aword.txt, there is a string:
    "\xea\xe0\xea+\xef\xee\xe7\xe2\xee\xed\xe8\xf2\xfc".

There is a first script:
f = open ("aword.txt", "r")
for line in f:
    print chardet.detect(line)
    b = line.decode('cp1251')
    print b

_RESULT_
{'confidence': 1.0, 'encoding': 'ascii'}
\xea\xe0\xea+\xef\xee\xe7\xe2\xee\xed\xe8\xf2\xfc

There is a second script:
line = "\xea\xe0\xea+\xef\xee\xe7\xe2\xee\xed\xe8\xf2\xfc"
print chardet.detect(line)
b = line.decode('cp1251')
print b

_RESULT_
{'confidence': 0.98999999999999999, 'encoding': 'windows-1251'}
как+позвонить

Why is reading from a file into a string variable is defined as ascii, 
but when it is clearly defined in the script is defined as cp1251. 
How do I solve this problem.


-- 
Only one 0_o



More information about the Python-list mailing list