Re: Factory for Struct-like classes

2008-08-21 Thread Gabriel Genellina
En Tue, 19 Aug 2008 12:43:27 -0300, eliben <[EMAIL PROTECTED]> escribió: On Aug 18, 11:16 am, Gabriel Genellina <[EMAIL PROTECTED]> wrote: On 13 ago, 14:46, eliben <[EMAIL PROTECTED]> wrote: > On Aug 13, 7:30 pm, Christian Heimes <[EMAIL PROTECTED]> wrote: > > Try named tuplehttp://code.active

Re: Factory for Struct-like classes

2008-08-20 Thread Dave Benjamin
eliben wrote: Whaaa? Named tuples are being added to Python? Neat! Is there any documentation on this? I can't seem to find anything on the web... It's not easy to find unless you recall where you've seen it: http://docs.python.org/dev/3.0/library/collections.html#collections.namedtuple Thank

Re: Factory for Struct-like classes

2008-08-20 Thread eliben
On Aug 21, 4:51 am, Dave Benjamin <[EMAIL PROTECTED]> wrote: > Christian Heimes wrote: > > eliben wrote: > >> Ruby's 'Scruct' class (http://ruby-doc.org/core/classes/Struct.html) > >> does this. I suppose it can be done with 'exec', but is there a more > >> Pythonic way ? > > > Try named tuplehttp:

Re: Factory for Struct-like classes

2008-08-20 Thread Dave Benjamin
Christian Heimes wrote: eliben wrote: Ruby's 'Scruct' class (http://ruby-doc.org/core/classes/Struct.html) does this. I suppose it can be done with 'exec', but is there a more Pythonic way ? Try named tuple http://code.activestate.com/recipes/500261/ A named tuple implementation is part of Py

Re: Factory for Struct-like classes

2008-08-20 Thread Gabriel Genellina
En Wed, 20 Aug 2008 04:00:08 -0300, Dan Lenski <[EMAIL PROTECTED]> escribi�: On Mon, 18 Aug 2008 08:28:53 -0700, Dan Lenski wrote: So is there a bug in the Python docs? Does __slots__ in fact work with subclasses of tuple? Anybody think that this may actually be a mistake in the Python doc

Re: Factory for Struct-like classes

2008-08-20 Thread Dan Lenski
On Mon, 18 Aug 2008 08:28:53 -0700, Dan Lenski wrote: > So is there a bug in the Python docs? Does __slots__ in fact work with > subclasses of tuple? > > Dan Anybody think that this may actually be a mistake in the Python docs? Who would I contact about getting them corrected? Dan -- http://

Re: Factory for Struct-like classes

2008-08-19 Thread eliben
On Aug 18, 11:16 am, Gabriel Genellina <[EMAIL PROTECTED]> wrote: > On 13 ago, 14:46, eliben <[EMAIL PROTECTED]> wrote: > > > On Aug 13, 7:30 pm, Christian Heimes <[EMAIL PROTECTED]> wrote: > > > > eliben wrote: > > > > Ruby's 'Scruct' class (http://ruby-doc.org/core/classes/Struct.html) > > > > do

Re: Factory for Struct-like classes

2008-08-18 Thread Dan Lenski
On Aug 13, 1:30 pm, Christian Heimes <[EMAIL PROTECTED]> wrote: > Trynamedtuplehttp://code.activestate.com/recipes/500261/ > > Anamedtupleimplementation is part of Python 2.6 and 3.0. For older > versions of Python use the recipe from activestate. > > Christian This named tuple recipe is pretty co

Re: Factory for Struct-like classes

2008-08-18 Thread Gabriel Genellina
On 13 ago, 14:46, eliben <[EMAIL PROTECTED]> wrote: > On Aug 13, 7:30 pm, Christian Heimes <[EMAIL PROTECTED]> wrote: > > > eliben wrote: > > > Ruby's 'Scruct' class (http://ruby-doc.org/core/classes/Struct.html) > > > does this. I suppose it can be done with 'exec', but is there a more > > > Pytho

Re: Factory for Struct-like classes

2008-08-14 Thread Matthew Wilson
On Thu 14 Aug 2008 11:19:06 AM EDT, Larry Bates wrote: > eliben wrote: >> Hello, >> >> I want to be able to do something like this: >> >> Employee = Struct(name, salary) >> >> And then: >> >> john = Employee('john doe', 34000) >> print john.salary I find something like this useful, especially

Re: Factory for Struct-like classes

2008-08-14 Thread Larry Bates
eliben wrote: Hello, I want to be able to do something like this: Employee = Struct(name, salary) And then: john = Employee('john doe', 34000) print john.salary Basically, Employee = Struct(name, salary) should be equivalent to: class Employee(object): def __init__(self, name, salary):

Re: Factory for Struct-like classes

2008-08-13 Thread Marc Christiansen
eliben <[EMAIL PROTECTED]> wrote: > Hello, > > I want to be able to do something like this: > > Employee = Struct(name, salary) > > And then: > > john = Employee('john doe', 34000) > print john.salary > > Basically, Employee = Struct(name, salary) should be equivalent to: > > class Employee(o

Re: Factory for Struct-like classes

2008-08-13 Thread eliben
On Aug 13, 7:30 pm, Christian Heimes <[EMAIL PROTECTED]> wrote: > eliben wrote: > > Ruby's 'Scruct' class (http://ruby-doc.org/core/classes/Struct.html) > > does this. I suppose it can be done with 'exec', but is there a more > > Pythonic way ? > > Try named tuplehttp://code.activestate.com/recipes

Re: Factory for Struct-like classes

2008-08-13 Thread Christian Heimes
eliben wrote: Ruby's 'Scruct' class (http://ruby-doc.org/core/classes/Struct.html) does this. I suppose it can be done with 'exec', but is there a more Pythonic way ? Try named tuple http://code.activestate.com/recipes/500261/ A named tuple implementation is part of Python 2.6 and 3.0. For ol

Re: Factory for Struct-like classes

2008-08-13 Thread Michele Simionato
On Aug 13, 6:43 pm, eliben <[EMAIL PROTECTED]> wrote: > Hello, > > I want to be able to do something like this: > > Employee = Struct(name, salary) > > And then: > > john = Employee('john doe', 34000) > print john.salary > > Basically, Employee = Struct(name, salary) should be equivalent to: > > cl