Re: Best practise implementation for equal by value objects

2008-08-08 Thread Terry Reedy
Slaunger wrote: OK, i am encouraged to carry on my quest with the eval(repr)) for my 'nice' classes. I just revisited the documentation for eval and noticed that there are optional globals and locals name space variables, that one could specify: http://docs.python.org/lib/built-in-funcs.html

Re: Best practise implementation for equal by value objects

2008-08-08 Thread Steven D'Aprano
On Fri, 08 Aug 2008 00:28:02 -0700, Slaunger wrote: > OK, i am encouraged to carry on my quest with the eval(repr)) for my > 'nice' classes. > I just revisited the documentation for eval and noticed that there are > optional globals > and locals name space variables, that one could specify: > > h

Re: Best practise implementation for equal by value objects

2008-08-08 Thread Slaunger
On 7 Aug., 21:19, Terry Reedy <[EMAIL PROTECTED]> wrote: > Slaunger wrote: > > On 6 Aug., 21:36, Terry Reedy <[EMAIL PROTECTED]> wrote: > > OK, the situation is more complicated than that then. In the case here > > though, > > the attributes would always be sinmple bulit-in types, where > > eval(re

Re: Best practise implementation for equal by value objects

2008-08-08 Thread Slaunger
On 7 Aug., 21:25, Paul Rubin wrote: > Terry Reedy <[EMAIL PROTECTED]> writes: > > So when the initializers for instances are all 'nice' (as for range), > > go for it (as in 'Age(10)').  And test it as you are by eval'ing the > > rep. Just accept that the eval will only wo

Re: Best practise implementation for equal by value objects

2008-08-07 Thread Paul Rubin
Terry Reedy <[EMAIL PROTECTED]> writes: > So when the initializers for instances are all 'nice' (as for range), > go for it (as in 'Age(10)'). And test it as you are by eval'ing the > rep. Just accept that the eval will only work in contexts with the > class name bound to the class. For built-in

Re: Best practise implementation for equal by value objects

2008-08-07 Thread Terry Reedy
Slaunger wrote: On 6 Aug., 21:36, Terry Reedy <[EMAIL PROTECTED]> wrote: OK, the situation is more complicated than that then. In the case here though, the attributes would always be sinmple bulit-in types, where eval(repr(x))==x or, where the attribute is a user-defined equal-by-value class

Re: Best practise implementation for equal by value objects

2008-08-07 Thread Duncan Booth
Steven D'Aprano <[EMAIL PROTECTED]> wrote: > I believe the recommendation for eval(repr(obj)) to give obj again is > meant as a convenience for the interactive interpreter, and even there > only for simple types like int or list. and even with types as simple as list and int the round tripping

Re: Best practise implementation for equal by value objects

2008-08-06 Thread Slaunger
On 7 Aug., 04:34, Steven D'Aprano <[EMAIL PROTECTED] cybersource.com.au> wrote: > On Wed, 06 Aug 2008 05:50:35 -0700, Slaunger wrote: > > Hi, > > > I am new here and relatively new to Python, so be gentle: > > > Is there a recommended generic implementation of __repr__ for objects > > equal by valu

Re: Best practise implementation for equal by value objects

2008-08-06 Thread Slaunger
On 6 Aug., 21:46, John Krukoff <[EMAIL PROTECTED]> wrote: > On Wed, 2008-08-06 at 05:50 -0700, Slaunger wrote: > > Hi, > > > I am new here and relatively new to Python, so be gentle: > > > Is there a recommended generic implementation of __repr__ for objects > > equal by value to assure that eval(r

Re: Best practise implementation for equal by value objects

2008-08-06 Thread Slaunger
On 6 Aug., 21:36, Terry Reedy <[EMAIL PROTECTED]> wrote: > Slaunger wrote: > > Hi, > > > I am new here and relatively new to Python, so be gentle: > > > Is there a recommended generic implementation of __repr__ for objects > > equal by value to assure that eval(repr(x)) == x independet of which > >

Re: Best practise implementation for equal by value objects

2008-08-06 Thread Steven D'Aprano
On Wed, 06 Aug 2008 05:50:35 -0700, Slaunger wrote: > Hi, > > I am new here and relatively new to Python, so be gentle: > > Is there a recommended generic implementation of __repr__ for objects > equal by value to assure that eval(repr(x)) == x independet of which > module the call is made from?

Re: Best practise implementation for equal by value objects

2008-08-06 Thread John Krukoff
On Wed, 2008-08-06 at 05:50 -0700, Slaunger wrote: > Hi, > > I am new here and relatively new to Python, so be gentle: > > Is there a recommended generic implementation of __repr__ for objects > equal by value to assure that eval(repr(x)) == x independet of which > module the call is made from?

Re: Best practise implementation for equal by value objects

2008-08-06 Thread Terry Reedy
Slaunger wrote: Hi, I am new here and relatively new to Python, so be gentle: Is there a recommended generic implementation of __repr__ for objects equal by value to assure that eval(repr(x)) == x independet of which module the call is made from? The CPython implementation gives up on that

Best practise implementation for equal by value objects

2008-08-06 Thread Slaunger
Hi, I am new here and relatively new to Python, so be gentle: Is there a recommended generic implementation of __repr__ for objects equal by value to assure that eval(repr(x)) == x independet of which module the call is made from? Example: class Age: def __init__(self, an_age): sel