<div dir="ltr">On Thu, Jan 9, 2014 at 2:54 PM, Paul Moore <div>> For example:  b'\x01\x00\xd1\x80\xd1\83\xd0\x80'<div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

<div class="im">
><br>
> If that were decoded using latin1 how would I then get the first two bytes<br>
> to the integer 256 and the last six bytes to their Cyrillic meaning?<br>
> (Apologies for not testing myself, short on time.)<br>
<br>
</div>I cannot conceive why you would. Slice the bytes then use<br>
struct.unpack on the first 2 bytes and decode on the last 6.</blockquote><div><br></div><div style>exactly.</div><div> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

 We're<br>
talking about using latin1 for cases where you want to treat the text<br>
as essentially ascii (with a few bits of binary junk you want to ignore). </blockquote><div><br></div><div style>as so --  I want to replace a bit of ascii text surrounded by arbitrary binary:</div><div style>(apologies for the py2...)<br>

</div><div style><div><br></div><div>In [24]: b</div><div>Out[24]: '\x01\x00\xd1\x80\xd1a name\xd0\x80'</div><div><br></div><div>In [25]: u = b.decode('latin-1')</div><div><br></div><div>In [26]: u2 = u.replace('a name', 'a different name')</div>

<div><br></div><div>In [28]: b2 = u2.encode('latin-1')<br></div><div><br></div><div>In [29]: b2</div><div>Out[29]: '\x01\x00\xd1\x80\xd1a different name\xd0\x80'</div><div><br></div></div><div style>-Chris</div>

<div style><br></div><div style><br></div><div style><br></div><div style><br></div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

Please don't take away the message that latin1 makes things<br>
"just like Python 2.X" - that's completely the wrong idea.<br>
<span class=""><font color="#888888"><br>
Paul<br>
</font></span><div class=""><div class="h5">_______________________________________________<br>
Python-Dev mailing list<br>
<a href="mailto:Python-Dev@python.org">Python-Dev@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-dev" target="_blank">https://mail.python.org/mailman/listinfo/python-dev</a><br>
Unsubscribe: <a href="https://mail.python.org/mailman/options/python-dev/chris.barker%40noaa.gov" target="_blank">https://mail.python.org/mailman/options/python-dev/chris.barker%40noaa.gov</a><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><br>Christopher Barker, Ph.D.<br>Oceanographer<br><br>Emergency Response Division<br>NOAA/NOS/OR&R            (206) 526-6959   voice<br>7600 Sand Point Way NE   (206) 526-6329   fax<br>

Seattle, WA  98115       (206) 526-6317   main reception<br><br><a href="mailto:Chris.Barker@noaa.gov" target="_blank">Chris.Barker@noaa.gov</a>
</div></div></div>