[Python-Dev] Python3 "complexity"
Chris Barker
chris.barker at noaa.gov
Fri Jan 10 00:25:52 CET 2014
More information about the Python-Dev mailing list
Fri Jan 10 00:25:52 CET 2014
- Previous message: [Python-Dev] Python3 "complexity"
- Next message: [Python-Dev] Python3 "complexity"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
> bytes
> > 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.
exactly.
> We're
> 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
binary:
(apologies for the py2...)
In [24]: b
Out[24]: '\x01\x00\xd1\x80\xd1a name\xd0\x80'
In [25]: u = b.decode('latin-1')
In [26]: u2 = u.replace('a name', 'a different name')
In [28]: b2 = u2.encode('latin-1')
In [29]: b2
Out[29]: '\x01\x00\xd1\x80\xd1a different name\xd0\x80'
-Chris
> Please don't take away the message that latin1 makes things
> "just like Python 2.X" - that's completely the wrong idea.
>
> Paul
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> https://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe:
> https://mail.python.org/mailman/options/python-dev/chris.barker%40noaa.gov
>
--
Christopher Barker, Ph.D.
Oceanographer
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...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20140109/cd7447fe/attachment.html>
- Previous message: [Python-Dev] Python3 "complexity"
- Next message: [Python-Dev] Python3 "complexity"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-Dev mailing list