Reading some FAQ, I see that __str__ is meant for human eyes.
But it seems that:
class X(object):
def __str__(self):
return str
def __repr__(self):
return repr
x = X()
d = {0 : x}
print d
{0: repr}
So if __str__ is meant for human eyes, then why isn't print using it!
--
Neal Becker wrote:
Reading some FAQ, I see that __str__ is meant for human eyes.
But it seems that:
class X(object):
def __str__(self):
return str
def __repr__(self):
return repr
x = X()
d = {0 : x}
print d
{0: repr}
So if __str__ is meant for human eyes, then why
Tino Wildenhain wrote:
Neal Becker wrote:
Reading some FAQ, I see that __str__ is meant for human eyes.
But it seems that:
class X(object):
def __str__(self):
return str
def __repr__(self):
return repr
x = X()
d = {0 : x}
print d
{0: repr}
So if __str__
Neal Becker wrote:
Reading some FAQ, I see that __str__ is meant for human eyes.
But it seems that:
class X(object):
def __str__(self):
return str
def __repr__(self):
return repr
x = X()
d = {0 : x}
print d
{0: repr}
So if __str__ is meant for human eyes,
Neal Becker wrote:
...
So if __str__ is meant for human eyes, then why isn't print using it!
it is:
print x
str
but dict just uses repr() for all its childs to print.
T.
That makes no sense to me. If I call 'print' on a container, why wouldn't it
recursively print on the contained
Tino Wildenhain wrote:
Neal Becker wrote:
...
So if __str__ is meant for human eyes, then why isn't print using it!
it is:
print x
str
but dict just uses repr() for all its childs to print.
T.
That makes no sense to me. If I call 'print' on a container, why
wouldn't it recursively
On Thu, 18 Dec 2008 09:51:01 -0500, Neal Becker ndbeck...@gmail.com wrote:
Tino Wildenhain wrote:
Neal Becker wrote:
...
So if __str__ is meant for human eyes, then why isn't print using it!
it is:
print x
str
but dict just uses repr() for all its childs to print.
T.
That makes no
Neal Becker wrote:
Tino Wildenhain wrote:
Neal Becker wrote:
...
So if __str__ is meant for human eyes, then why isn't print using
it!
it is:
print x
str
but dict just uses repr() for all its childs to print.
T.
That makes no sense to me. If I call 'print' on a container, why
Diez B. Roggisch wrote:
Neal Becker wrote:
Tino Wildenhain wrote:
Neal Becker wrote:
...
So if __str__ is meant for human eyes, then why isn't print using
it!
it is:
print x
str
but dict just uses repr() for all its childs to print.
T.
That makes no sense to me. If I call
Neal Becker wrote:
Diez B. Roggisch wrote:
Neal Becker wrote:
Tino Wildenhain wrote:
Neal Becker wrote:
...
So if __str__ is meant for human eyes, then why isn't print using
it!
it is:
print x
str
but dict just uses repr() for all its childs to print.
T.
That makes no
Diez B. Roggisch wrote:
Yep. And it's easy enough if you don't care about them being different..
def __repr__(self):
return str(self)
If I ever wanted __str__ and __repr__ to return the same thing, I would
make them equal:
def __str__(self):
return 'whatever you want'
__repr__ =
Quoth Diez B. Roggisch de...@nospam.web.de:
Neal Becker wrote:
Tino Wildenhain wrote:
Neal Becker wrote:
...
That makes no sense to me. If I call 'print' on a container, why
wouldn't it recursively print on the contained objects? Since print
means call str, printing a
Neal Becker wrote:
Tino Wildenhain wrote:
Neal Becker wrote:
Reading some FAQ, I see that __str__ is meant for human eyes.
But it seems that:
class X(object):
def __str__(self):
return str
def __repr__(self):
return repr
x = X()
d = {0 : x}
print d
{0:
Mel wrote:
Neal Becker wrote:
Tino Wildenhain wrote:
Neal Becker wrote:
Reading some FAQ, I see that __str__ is meant for human eyes.
But it seems that:
class X(object):
def __str__(self):
return str
def __repr__(self):
return repr
x = X()
d = {0 : x}
On Thu, 2008-12-18 at 13:35 -0500, Neal Becker wrote:
Mel wrote:
Neal Becker wrote:
Tino Wildenhain wrote:
Neal Becker wrote:
Reading some FAQ, I see that __str__ is meant for human eyes.
But it seems that:
class X(object):
def __str__(self):
return str
Mikael Olofsson wrote:
Diez B. Roggisch wrote:
Yep. And it's easy enough if you don't care about them being different..
def __repr__(self):
return str(self)
If I ever wanted __str__ and __repr__ to return the same thing, I would
make them equal:
def __str__(self):
return 'whatever
J. Cliff Dyer wrote:
... how an object prints itself is up to that object and that object alone
If I wanted to implement a list-like class that doesn't show it's elements at
all when printed, but instead shows its length, I am free to do so.
For example:
hl = HiddenList(1,2,3)
hl
Neal Becker wrote:
Mel wrote:
Neal Becker wrote:
Tino Wildenhain wrote:
Neal Becker wrote:
Reading some FAQ, I see that __str__ is meant for human eyes.
But it seems that:
class X(object):
def __str__(self):
return str
def __repr__(self):
return repr
x =
En Thu, 18 Dec 2008 14:05:32 -0200, Mikael Olofsson mik...@isy.liu.se
escribió:
Diez B. Roggisch wrote:
Yep. And it's easy enough if you don't care about them being different..
def __repr__(self):
return str(self)
If I ever wanted __str__ and __repr__ to return the same thing, I would
On Thu, 18 Dec 2008 10:49:27 -0500, Neal Becker wrote:
So if I want to overload something in my custom class, so that I get a
nice string whether it's printed directly, or as part of a container,
what is the recommendation? Overload both __str__ and __repr__?
Either or both or neither,
On Thu, 18 Dec 2008 22:11:27 -0200, Gabriel Genellina wrote:
En Thu, 18 Dec 2008 14:05:32 -0200, Mikael Olofsson mik...@isy.liu.se
escribió:
...
If I ever wanted __str__ and __repr__ to return the same thing, I would
make them equal:
def __str__(self):
return 'whatever you want'
Steven D'Aprano wrote:
BTW Neal, your posts aren't word wrapped. When I read your posts, I get
each paragraph as one extremely LONG line scrolling way out to the side.
That's against the Internet standards for both email and Usenet, so could
you please configure your client to word-wrap at
On Dec 18, 1:27 pm, Robert Kern robert.k...@gmail.com wrote:
Mikael Olofsson wrote:
Diez B. Roggisch wrote:
Yep. And it's easy enough if you don't care about them being different..
def __repr__(self):
return str(self)
If I ever wanted __str__ and __repr__ to return the same thing,
On Dec 18, 9:53 am, Diez B. Roggisch de...@nospam.web.de wrote:
Neal Becker wrote:
Diez B. Roggisch wrote:
Neal Becker wrote:
Tino Wildenhain wrote:
Neal Becker wrote:
...
So if __str__ is meant for human eyes, then why isn't print using
it!
it is:
print x
str
but
Bruno Desthuilliers wrote:
def __str__(self):
return %s:%s % (self.commiterID_, self.commits_)
I would write that in the following way:
def __str__(self):
return %(commiterID_)s:%(commits_)s % self.__dict__
More explicit IMHO. And easier to maintain, especially if the string
would
Mikael Olofsson a écrit :
Bruno Desthuilliers wrote:
def __str__(self):
return %s:%s % (self.commiterID_, self.commits_)
I would write that in the following way:
def __str__(self):
return %(commiterID_)s:%(commits_)s % self.__dict__
More explicit IMHO. And easier to maintain,
Konstantinos Pachopoulos a écrit :
Hi,
i have the following class:
===
class CmterIDCmts:
def __init__(self,commiterID,commits):
self.commiterID_=long(commiterID)
self.commits_=long(commits)
def __str__(self):
Hi,
i have the following class:
===
class CmterIDCmts:
def __init__(self,commiterID,commits):
self.commiterID_=long(commiterID)
self.commits_=long(commits)
def __str__(self):
s=
I read here recently that the __str__ method of a list calls the
__repr__ method of each of its members. So you need to add a __repr__
method to your class:
class CmterIDCmts:
def __init__(self,commiterID,commits):
self.commiterID_=long(commiterID)
self.commits_=long(commits)
On Sep 20, 10:08 pm, Konstantinos Pachopoulos [EMAIL PROTECTED]
wrote:
The __str__ method of list doesn't seem to call the __str__ method of
the objects
ie, __str__ is not equicalent to the Java toString() method... Anyway,
how can i fix this?
For whatever reason, __str__ of list calls
30 matches
Mail list logo