Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #108032
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Erik <python@lucidity.plus.com> |
| Newsgroups | comp.lang.python |
| Subject | Re: Need help understanding list structure |
| Date | Mon, 2 May 2016 22:48:33 +0100 |
| Lines | 28 |
| Message-ID | <mailman.329.1462225716.32212.python-list@python.org> (permalink) |
| References | <d6b0c524-f020-4726-b91a-517b2e8024ea@googlegroups.com> <5727CB31.5060309@lucidity.plus.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=windows-1252; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Trace | news.uni-berlin.de x7WckbD7VMq31zP3ZW6QIQSvP47dN/oRBl2i4FYTzBmA== |
| 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.001 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'method.': 0.05; 'method,': 0.07; 'objects,': 0.07; 'subject:help': 0.07; 'iterate': 0.09; 'pointers': 0.09; 'itself.': 0.11; 'from:addr:python': 0.16; 'invoked,': 0.16; 'iterating': 0.16; 'pointers.': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'should.': 0.16; 'textual': 0.16; 'wrote:': 0.16; 'memory': 0.17; 'string': 0.17; 'element': 0.18; 'to:2**1': 0.21; 'text,': 0.22; "python's": 0.23; 'represents': 0.23; 'header:In-Reply-To:1': 0.24; 'header:User-Agent:1': 0.26; 'subject:list': 0.26; 'to:no real name:2**1': 0.27; 'function': 0.28; 'actual': 0.28; 'prints': 0.29; 'subject:skip:u 10': 0.29; 'objects': 0.29; 'print': 0.30; 'classes': 0.30; 'implement': 0.32; 'says': 0.32; 'received:84': 0.32; 'class': 0.33; 'list': 0.34; 'text': 0.35; 'according': 0.36; 'list,': 0.36; 'instead': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'expect': 0.37; 'method': 0.37; 'someone': 0.38; 'why': 0.39; 'whatever': 0.39; 'received:192': 0.39; 'to:addr:python.org': 0.40; 'where': 0.40; 'hope': 0.61; 'address': 0.61; 'subject:Need': 0.61; 'email addr:gmail.com': 0.62; 'charset:windows-1252': 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=d6bQx1Csmutac+MnUcj9pQ==:117 a=d6bQx1Csmutac+MnUcj9pQ==:17 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=N659UExz7-8A:10 a=pGLkceISAAAA:8 a=r1hPsYAYBzlKzWqk7GkA:9 a=gq2ilWT529ViV0Om:21 a=py93SxM2iaYqzZFm:21 a=pILNOxqGKmIA:10 |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.7.2 |
| In-Reply-To | <d6b0c524-f020-4726-b91a-517b2e8024ea@googlegroups.com> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.22 |
| 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> |
| X-Mailman-Original-Message-ID | <5727CB31.5060309@lucidity.plus.com> |
| X-Mailman-Original-References | <d6b0c524-f020-4726-b91a-517b2e8024ea@googlegroups.com> |
| Xref | csiph.com comp.lang.python:108032 |
Show key headers only | View raw
On 02/05/16 22:30, moa47401@gmail.com wrote: > Can someone help me understand why or under what circumstances a list > shows pointers instead of the text data? When Python's "print" statement/function is invoked, it will print the textual representation of the object according to its class's __str__ or __repr__ method. That is, the print function prints out whatever text the class says it should. For classes which don't implement a __str__ or __repr__ method, then the text "<CLASS object at ADDRESS>" is used - where CLASS is the class name and ADDRESS is the "memory pointer". > If I iterate over the list, I do get the actual text of each element > and am able to use it. > > Also, if I iterate over the list and place each element in a new list > using append, then each element in the new list is the text I expect > not memory pointers. Look at the __iter__ method of the class of the object you are iterating over. I suspect that it returns string objects, not the objects that are in the list itself. String objects have a __str__ or __repr__ method that represents them as the text, so that is what 'print' will output. Hope that helps, E.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Need help understanding list structure moa47401@gmail.com - 2016-05-02 14:30 -0700
Re: Need help understanding list structure Erik <python@lucidity.plus.com> - 2016-05-02 22:48 +0100
Re: Need help understanding list structure moa47401@gmail.com - 2016-05-02 15:33 -0700
Re: Need help understanding list structure Michael Torrie <torriem@gmail.com> - 2016-05-02 17:25 -0600
Re: Need help understanding list structure Ben Finney <ben+python@benfinney.id.au> - 2016-05-03 09:43 +1000
Re: Need help understanding list structure moa47401@gmail.com - 2016-05-03 06:21 -0700
Re: Need help understanding list structure Chris Angelico <rosuav@gmail.com> - 2016-05-03 23:47 +1000
Re: Need help understanding list structure moa47401@gmail.com - 2016-05-03 09:01 -0700
RE: Need help understanding list structure Dan Strohl <D.Strohl@F5.com> - 2016-05-03 16:52 +0000
Re: Need help understanding list structure moa47401@gmail.com - 2016-05-03 10:31 -0700
RE: Need help understanding list structure Dan Strohl <D.Strohl@F5.com> - 2016-05-03 17:54 +0000
Use __repr__ to show the programmer's representation (was: Need help understanding list structure) Ben Finney <ben+python@benfinney.id.au> - 2016-05-04 04:14 +1000
RE: Use __repr__ to show the programmer's representation (was: Need help understanding list structure) Dan Strohl <D.Strohl@F5.com> - 2016-05-03 18:35 +0000
Re: Use __repr__ to show the programmer's representation (was: Need help understanding list structure) moa47401@gmail.com - 2016-05-03 12:24 -0700
Re: Use __repr__ to show the programmer's representation (was: Need help understanding list structure) Random832 <random832@fastmail.com> - 2016-05-03 15:37 -0400
Re: Need help understanding list structure MRAB <python@mrabarnett.plus.com> - 2016-05-03 20:57 +0100
Re: Use __repr__ to show the programmer's representation (was: Need help understanding list structure) Chris Angelico <rosuav@gmail.com> - 2016-05-04 09:40 +1000
csiph-web