>> __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
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
11 matches
Mail list logo