[Python-Dev] Round Bug in Python 1.6?
Andrew Dalke
dalke at acm.org
Fri Apr 7 09:32:54 EDT 2000
Greg Ward exclaimed:
>Oh, joy! oh happiness! someday soon, I may be able to type
>"blah.__doc__" at the interactive prompt and get a readable result!
I agree. I write __str__ to be human readable, while __repr__
is more mean to be used in evals. I have code which looks like:
def __repr__(self):
return "%s(%s, %s)" % (self.__class__.__name__,
repr(self.data),
repr(self.alphabet))
def __str__(self):
if len(self.data) > 60:
s = repr(self.data[:60] + " ...")
else:
s = repr(self.data)
return "%s(%s, %s)" % (self.__class__.__name__, s,
repr(self.alphabet))
The size of self.data could be megabytes, and I don't want that
scrolling line after line up the screen when in interactive mode.
I would much rather have the __str__ version which only shows
the first 60 characters.
Andrew
dalke at acm.org
More information about the Python-list
mailing list