[Python-Dev] Decimal(unicode)
M.-A. Lemburg
mal at egenix.com
Wed Mar 26 10:29:58 CET 2008
On 2008-03-26 07:11, Martin v. Löwis wrote:
>> For binary representations, we already have the struct module to handle
>> the parsing, but for byte sequences with embedded ASCII digits it's
>> reasonably common practice to use strings along with the respective type
>> constructors.
>
> Sure, but why can't you write
>
> foo = int(bar[start:stop].decode("ascii"))
>
> then? Explicit is better than implicit.
Agreed.
The whole purpose of Unicode is to store text. Data from a file
isn't text per-se. You have to tell Python that a particular set of
bytes is to be interpreted as text and that only works by explicitly
converting the bytes to text.
Numbers or digits aren't any different in this context.
b"1234" is just a sequence of bytes and could well represent
the binary encoding of an integer, the start of a base64 encoded
image, an SSH key or an audio file.
Don't get fooled by the looks of b"1234". It's really just a
shorter way of writing 0x31 0x32 0x33 0x34.
--
Marc-Andre Lemburg
eGenix.com
Professional Python Services directly from the Source (#1, Mar 26 2008)
>>> Python/Zope Consulting and Support ... http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/
________________________________________________________________________
:::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! ::::
eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
Registered at Amtsgericht Duesseldorf: HRB 46611
More information about the Python-Dev
mailing list