[Python-Dev] Python3 "complexity"
chris.barker at noaa.gov
Fri Jan 10 00:25:52 CET 2014
On Thu, Jan 9, 2014 at 2:54 PM, Paul Moore
> For example: b'\x01\x00\xd1\x80\xd1\83\xd0\x80'
> > If that were decoded using latin1 how would I then get the first two
> > to the integer 256 and the last six bytes to their Cyrillic meaning?
> > (Apologies for not testing myself, short on time.)
> I cannot conceive why you would. Slice the bytes then use
> struct.unpack on the first 2 bytes and decode on the last 6.
> talking about using latin1 for cases where you want to treat the text
> as essentially ascii (with a few bits of binary junk you want to ignore).
as so -- I want to replace a bit of ascii text surrounded by arbitrary
(apologies for the py2...)
In : b
Out: '\x01\x00\xd1\x80\xd1a name\xd0\x80'
In : u = b.decode('latin-1')
In : u2 = u.replace('a name', 'a different name')
In : b2 = u2.encode('latin-1')
In : b2
Out: '\x01\x00\xd1\x80\xd1a different name\xd0\x80'
> Please don't take away the message that latin1 makes things
> "just like Python 2.X" - that's completely the wrong idea.
> Python-Dev mailing list
> Python-Dev at python.org
Christopher Barker, Ph.D.
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker at noaa.gov
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-Dev