On Dec 18, 9:53 am, "Diez B. Roggisch" 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:
On Dec 18, 1:27 pm, Robert Kern 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, I wou
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 Thu, 18 Dec 2008 22:11:27 -0200, Gabriel Genellina wrote:
> En Thu, 18 Dec 2008 14:05:32 -0200, Mikael Olofsson
> 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'
>> __repr__
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, wha
En Thu, 18 Dec 2008 14:05:32 -0200, Mikael Olofsson
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
make them equal:
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"
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
hl
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
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):
> d
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):
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"
>>>
>
Quoth "Diez B. Roggisch" :
> 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 co
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__ = __s
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 dic
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
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
On Thu, 18 Dec 2008 09:51:01 -0500, 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 ca
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 conta
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 ob
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 "
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
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 w
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
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 ea
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
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)
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
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)
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=""
s+="<"+str(self.commiterID_
30 matches
Mail list logo