On Wed, May 4, 2016 at 4:35 AM, Dan Strohl via Python-list
wrote:
> I also have never actually used repr() to create code that could be fed back
> to the interpreter (not saying it isn’t done, just that I haven’t run into
> needing it), and there are so many of the
On 2016-05-03 18:54, Dan Strohl via Python-list wrote:
I added a __repr__ method at the end of the gedcom library like so:
def __repr__(self):
""" Format this element as its original string """
result = repr(self.level())
if self.pointer() != "":
result +=
On Tue, May 3, 2016, at 15:24, moa47...@gmail.com wrote:
> I also wanted to understand what character set it was returning. I was
> giving it a gedcom file with ansel encoding, which is normal. My
> genealogy program can also export its database to gedcom using UTF-8 and
> Unicode. But both of
quote - (Though to be fair, I don't really know what the actual problem was, so
I might provide a different approach with a different goal )
Originally I was trying to understand the exact structure of the list being
returned by the gedcom library. It worked as it was, but I wanted to add
> > One other point for you, if your "__repr__(self)" code is the same as
> > the "__str__(self)" code (which it looks like it is, at a glance at
> > least), you can instead reference the __str__ method and save having a
> > duplicate code block...
>
> Alternatively, consider: the ‘__repr__’
Dan Strohl via Python-list writes:
> One other point for you, if your "__repr__(self)" code is the same as
> the "__str__(self)" code (which it looks like it is, at a glance at
> least), you can instead reference the __str__ method and save having a
> duplicate code
> I added a __repr__ method at the end of the gedcom library like so:
>
> def __repr__(self):
> """ Format this element as its original string """
> result = repr(self.level())
> if self.pointer() != "":
> result += ' ' + self.pointer()
> result += ' '
I added a __repr__ method at the end of the gedcom library like so:
def __repr__(self):
""" Format this element as its original string """
result = repr(self.level())
if self.pointer() != "":
result += ' ' + self.pointer()
result += ' ' + self.tag()
Take a look at the docs for
print() https://docs.python.org/3.5/library/functions.html#print
str() https://docs.python.org/3.5/library/stdtypes.html#str
repr() https://docs.python.org/3.5/library/functions.html#repr
When you do "print(object)", python will run everything through str() and
At the risk of coming across as a complete dunder-head, I think my confusion
has to do with the type of data the library returns in the list. Any kind of
text or integer list I manually create, doesn't do this.
See my questions down below at the end.
If I run the following statements on the
On Tue, May 3, 2016 at 11:21 PM, wrote:
> Thanks for the replies. I definitely need a better understanding of " object at ADDRESS>" when using Python objects. So far no luck with web
> searches or my Python books. Could someone point (no pun intended) me to a
> good
Thanks for the replies. I definitely need a better understanding of "" when using Python objects. So far no luck with web searches
or my Python books. Could someone point (no pun intended) me to a good
resource?
Not that it matters, but the reason I got off track is there are pointers
within
moa47...@gmail.com writes:
> Am I correct in assuming that parsing a large text file would be
> quicker returning pointers instead of strings?
What do you mean by “return a pointer”? Python doesn't have pointers.
In the Python language, a container type (such as ‘set’, ‘list’, ‘dict’,
etc.)
On 05/02/2016 04:33 PM, moa47...@gmail.com wrote:
> Yes, that does help. You're right. The author of the library I'm
> using didn't implement either a __str__ or __repr__ method. Am I
> correct in assuming that parsing a large text file would be quicker
> returning pointers instead of strings?
> 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__
On 02/05/16 22:30, moa47...@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
I've been using an old text parsing library and have been able to accomplish
most of what I wanted to do. But I don't understand the list structure it uses
well enough to build additional methods.
If I print the list, it has thousands of elements within its brackets separated
by commas as I
17 matches
Mail list logo