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
>> __repr__ shouldn't be anything, if you don't have an actual need for
>> it. Neither should __str__.
Simon> Oh, I don't know. __str__ is so frequently useful in debugging
Simon> and logging that I always try and do something useful with it.
And sometimes __repr__ inherited fro
Simon Brunning wrote:
> On 6/15/05, Peter Hansen <[EMAIL PROTECTED]> wrote:
>>__repr__ shouldn't be anything, if you don't have an actual need for it.
>> Neither should __str__.
>
> Oh, I don't know. __str__ is so frequently useful in debugging and
> logging that I always try and do something use
On 6/15/05, Peter Hansen <[EMAIL PROTECTED]> wrote:
> __repr__ shouldn't be anything, if you don't have an actual need for it.
> Neither should __str__.
Oh, I don't know. __str__ is so frequently useful in debugging and
logging that I always try and do something useful with it.
--
Cheers,
Simo
In article <[EMAIL PROTECTED]>,
"John Roth" <[EMAIL PROTECTED]> wrote:
> "Donn Cave" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> > Quoth "John Roth" <[EMAIL PROTECTED]>:
> > ...
> > | str() should be something that's meaningful to a human being when
> > | it's printed or othe
"Donn Cave" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Quoth "John Roth" <[EMAIL PROTECTED]>:
> ...
> | str() should be something that's meaningful to a human being when
> | it's printed or otherwise rendered.
>
> I can't believe how many people cite this explanation - meaningf
Quoth "John Roth" <[EMAIL PROTECTED]>:
...
| str() should be something that's meaningful to a human being when
| it's printed or otherwise rendered.
I can't believe how many people cite this explanation - meaningful,
friendly, pretty to a human being. What on earth does this mean,
that couldn't b
"Jan Danielsson" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Sorry, but I Just Don't Get It. I did search the 'net, I did read the
> FAQ, but I'm too dumb to understand.
>
> As far as I can gather, __str__ is just a representation of the
> object. For instance:
>
> class Serv
Jan Danielsson wrote:
> Sorry, but I Just Don't Get It. I did search the 'net, I did read the
> FAQ, but I'm too dumb to understand.
Say we define a string "s" as follows:
>>> s = 'hello'
If we print "s", we see its string form (__str__):
>>> print s
hello
However, if we just examine "s",
On Wednesday 15 June 2005 08:06 am, Sébastien Boisgérault wrote:
> Jan Danielsson a écrit :
> >However, I don't understand what __repr__ should be.
> It is an *exact* (if possible) description of the object's content,
> nicely packaged into a string.
However, this is often not the case. Freque
In article <[EMAIL PROTECTED]>,
Jan Danielsson <[EMAIL PROTECTED]> wrote:
> Sorry, but I Just Don't Get It. I did search the 'net, I did read the
> FAQ, but I'm too dumb to understand.
>
>As far as I can gather, __str__ is just a representation of the
> object.
No, it is not. It is a con
Jan Danielsson wrote:
> Sorry, but I Just Don't Get It. I did search the 'net, I did read the
> FAQ, but I'm too dumb to understand.
>
> As far as I can gather, __str__ is just a representation of the
> object. [snip]
> However, I don't understand what __repr__ should be.
__repr__ shouldn't b
Basically __repr__ should return a string representaion of the object,
and __str__ should return a user-friendly pretty string. So maybe:
class Person:
...
def __repr__(self):
return '' % (self.name, self.age, self.sign)
def __str__(self):
return self.name
See this for a bett
Well, It means that eval(repr(x)) == x if at all possible.
Basically:
repr('abc') -> 'abc'
str('abc') -> abc
You'll notice that 'abc' is a valid python expression for the string,
while abc is not a valid string expression.
Andreas
On Wed, Jun 15, 2005 at 02:46:04PM +0200, Jan Danielsson wrote:
>
Errata:
>>> str(0.1)
'0.1'
>>> str("it's a bad idea")
"it's a bad idea"
>>> repr(0.1)
' 0.10001'
>>> repr("it's a bad idea")
'"it\'s a bad idea"'
SB
--
http://mail.python.org/mailman/listinfo/python-list
Jan Danielsson a écrit :
> Sorry, but I Just Don't Get It. I did search the 'net, I did read the
> FAQ, but I'm too dumb to understand.
>
>As far as I can gather, __str__ is just a representation of the
> object.
... yep, and this representation is built for human eyes. Don't
worry too much if
Sorry, but I Just Don't Get It. I did search the 'net, I did read the
FAQ, but I'm too dumb to understand.
As far as I can gather, __str__ is just a representation of the
object. For instance:
class ServerConnection:
def __str__(self):
buf = "Server: " + self.name + "\n"
buf +
40 matches
Mail list logo