Re: class declaration shortcut
- From: Steven Bethard <steven.bethard@xxxxxxxxx>
- Date: Wed, 28 Feb 2007 14:21:05 -0700
Luis M. González wrote:
I've come across a code snippet in www.rubyclr.com where they show how
easy it is to declare a class compared to equivalent code in c#.
I wonder if there is any way to emulate this in Python.
The code is as follows:
Person = struct.new( :name, :birthday, :children)
How about something like::
class Person(Record):
__slots__ = 'name', 'birthday', 'children'
You can then use the class like::
person = Person('Steve', 'April 25', [])
assert person.name == 'Steve'
assert person.birthday == 'April 25'
assert not person.children
Is that what you were looking for? If so, the recipe for the Record class is here:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/502237
STeVe
.
- Follow-Ups:
- Re: class declaration shortcut
- From: Luis M. González
- Re: class declaration shortcut
- References:
- class declaration shortcut
- From: Luis M. González
- class declaration shortcut
- Prev by Date: Re: Extract String From Enclosing Tuple
- Next by Date: Re: How to check for remaining hard drive space in Windows?
- Previous by thread: Re: class declaration shortcut
- Next by thread: Re: class declaration shortcut
- Index(es):
Relevant Pages
|