Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #100391
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Erik <python@lucidity.plus.com> |
| Newsgroups | comp.lang.python |
| Subject | Re: Weird list conversion |
| Date | Sun, 13 Dec 2015 20:28:16 +0000 |
| Lines | 32 |
| Message-ID | <mailman.218.1450038500.12405.python-list@python.org> (permalink) |
| References | <5926ced0-5b86-41f2-81e8-55cc6f71b78c@googlegroups.com> <mailman.216.1450036662.12405.python-list@python.org> <3193bf38-82c3-4538-b500-5e23158898e6@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=windows-1252; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Trace | news.uni-berlin.de 995OWunalQVrwSyI2npm8QZAdafU+tB3y7SGFuoV73Yw== |
| Return-Path | <python@lucidity.plus.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.003 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'strings.': 0.07; 'creighton': 0.09; 'notation.': 0.09; 'python': 0.10; 'editor,': 0.16; 'from:addr:python': 0.16; 'hex': 0.16; "objects'": 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; 'string': 0.17; 'byte': 0.18; 'laura': 0.18; '(in': 0.18; '>>>': 0.20; 'all,': 0.20; '2015': 0.20; 'to:2**1': 0.21; 'ascii': 0.22; 'dec': 0.23; 'header:In-Reply-To:1': 0.24; 'header:User-Agent:1': 0.26; 'subject:list': 0.26; 'always,': 0.29; 'notation': 0.29; 'print': 0.30; 'code': 0.30; 'help!': 0.30; 'december': 0.32; 'received:84': 0.32; 'returned': 0.32; 'rule': 0.33; 'case,': 0.34; 'file': 0.34; 'list': 0.34; 'according': 0.36; 'to:addr :python-list': 0.36; 'subject:: ': 0.37; 'method': 0.37; 'turn': 0.37; 'thanks': 0.37; 'no,': 0.38; 'why': 0.39; 'data': 0.39; 'does': 0.39; 'received:192': 0.39; 'to:addr:python.org': 0.40; 'called': 0.40; 'charset:windows-1252': 0.62; 'skip:n 10': 0.62; "class's": 0.84 |
| X-CM-Score | 0.00 |
| X-CNFS-Analysis | v=2.1 cv=Iat6Ijea c=1 sm=1 tr=0 a=Ypmeq7T0cKALDUsRPCToMg==:117 a=Ypmeq7T0cKALDUsRPCToMg==:17 a=0Bzu9jTXAAAA:8 a=EBOSESyhAAAA:8 a=N659UExz7-8A:10 a=Wag2qbStRjlIRV8WpUcA:9 a=pILNOxqGKmIA:10 |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.4.0 |
| In-Reply-To | <3193bf38-82c3-4538-b500-5e23158898e6@googlegroups.com> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.20+ |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Xref | csiph.com comp.lang.python:100391 |
Show key headers only | View raw
On 13/12/15 20:05, KP wrote:
> On Sunday, 13 December 2015 11:57:57 UTC-8, Laura Creighton wrote:
>> In a message of Sun, 13 Dec 2015 11:45:19 -0800, KP writes:
>>> Hi all,
>>>
>>> f = open("stairs.bin", "rb") data = list(f.read(16)) print data
>>>
>>> returns
>>>
>>> ['=', '\x04', '\x00', '\x05', '\x00', '\x01', '\x00', '\x00',
>>> '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00']
>>>
>>> The first byte of the file is 0x3D according to my hex editor, so
>>> why does Python return '=' and not '\x3D'?
>>>
>>> As always, thanks for any help!
>>
>> 0x3d is the ascii code for '='
>
> I am aware of that - so is the rule that non-printables are returned
> in hex notation whereas printables come in their ASCII
> representation?
No, what is _returned_ is a list of one-byte strings.
When you call "print", then the list class's __repr__() method is called
which in turn calls the contained objects' __repr__() methods in turn -
it is those methods (in this case, they are all the string class's)
which is deciding to render ASCII printable characters as just their
value and ASCII non-printable characters using their hex notation.
E.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Weird list conversion high5storage@gmail.com - 2015-12-13 11:45 -0800
Re: Weird list conversion Laura Creighton <lac@openend.se> - 2015-12-13 20:57 +0100
Re: Weird list conversion KP <kai.peters@gmail.com> - 2015-12-13 12:05 -0800
Re: Weird list conversion Erik <python@lucidity.plus.com> - 2015-12-13 20:28 +0000
Re: Weird list conversion Ian Kelly <ian.g.kelly@gmail.com> - 2015-12-13 13:28 -0700
Re: Weird list conversion Erik <python@lucidity.plus.com> - 2015-12-13 20:31 +0000
Re: Weird list conversion Larry Hudson <orgnut@yahoo.com> - 2015-12-13 12:42 -0800
Re: Weird list conversion Chris Angelico <rosuav@gmail.com> - 2015-12-14 08:09 +1100
Re: Weird list conversion Ian Kelly <ian.g.kelly@gmail.com> - 2015-12-13 12:59 -0700
csiph-web