Re: FAQ: __str__ vs __repr__

2005-06-21 Thread Skip Montanaro
>> __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

Re: FAQ: __str__ vs __repr__

2005-06-21 Thread Peter Hansen
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

Re: FAQ: __str__ vs __repr__

2005-06-21 Thread Simon Brunning
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

Re: FAQ: __str__ vs __repr__

2005-06-15 Thread Dave Benjamin
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",

Re: FAQ: __str__ vs __repr__

2005-06-15 Thread Terry Hancock
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

Re: FAQ: __str__ vs __repr__

2005-06-15 Thread Donn Cave
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

Re: FAQ: __str__ vs __repr__

2005-06-15 Thread Peter Hansen
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

Re: FAQ: __str__ vs __repr__

2005-06-15 Thread Greg Krohn
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

Re: FAQ: __str__ vs __repr__

2005-06-15 Thread Andreas Kostyrka
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: >

Re: FAQ: __str__ vs __repr__

2005-06-15 Thread =?iso-8859-1?q?S=E9bastien_Boisg=E9rault?=
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

Re: FAQ: __str__ vs __repr__

2005-06-15 Thread =?iso-8859-1?q?S=E9bastien_Boisg=E9rault?=
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