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 _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com