Standing Objects ... possible?
Jason Orendorff
jason at jorendorff.com
Sat Feb 2 23:08:46 EST 2002
Philip Swartzleonard writes:
> What i want is a construct like:
>
> object Foo( ancestor ):
> pass
Yep, it exists.
class MyObject:
""" This is the class of object I want to create """
def __init__(self, name, bases, dict):
# ...do whatever you want here...
print "NOTE: creating a MyObject with name =", name
# Here I make the ancestor...
ancestor = MyObject('ancestor', (), {})
# Now I can make objects like this:
class Foo(ancestor):
x = 3
y = 4
# ...
print Foo # voila!
## Jason Orendorff http://www.jorendorff.com/
More information about the Python-list
mailing list