decoding a byte array that is unicode escaped?
strong.drug at gmail.com
strong.drug at gmail.com
Mon Aug 13 07:55:20 EDT 2012
пятница, 6 ноября 2009 г., 12:48:47 UTC+4 пользователь sam написал:
> I am simply trying to display this copyright symbol on a webpage, so
> how do I encode the byte array to utf-8 given that it is 'escape
> encoded' in the above way? I tried:
>
> responseByteArray.decode('utf-8')
> and responseByteArray.decode('unicode_escape')
> and str(responseByteArray).
>
> I am using Python 3.1.
I had some problem with reading zip archive in raw (binary) mode.
I solve it this way
....
open (filename, 'rb').read ().encode('string_escape')
# now we had strings with strange symbols are escaped
# than we can handle it without decoding excepions for example:
body = '\r\n'.join (lines)
....
# if we have unescaped strings we can get an exception there
# after opertions, we needed we must unescape all content
# and drop it out to network (in my case)
body = body.decode('string-escape')
....
# then we can send so to the server
connection.request('POST', upload_url, body, headers)
BR)
More information about the Python-list
mailing list