Moved to 2.7 c 3.2 version and now the elementary 3.2 action does not work: writing unicode strings to a file.
I get a page from the network and parse its lxml, I get, for example, the line:
u'+100500 - \xd0\x9b\xd1\x83\xd1\x87\xd1\x88\xd0\xb5\xd0\xb5 \xd0\x98\xd0\xbd\xd1\x82\xd0\xb5\xd1\x80\xd0\xb2\xd1\x8c\xd1\x8e' When trying to write this line to the file a bunch of errors (st - this line):
>>> open(r'c:\text.txt', 'w' ).write(st.encode('cp1251')) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "e:\Python27\lib\encodings\cp1251.py", line 12, in encode return codecs.charmap_encode(input,errors,encoding_table) UnicodeEncodeError: 'charmap' codec can't encode characters in position 10-18: c haracter maps to <undefined> If you ignore errors with .encode ('cp1251', errors = 'ignore') then only spaces and numbers remain from the string.
The source string in utf. How to write a string to a file?