object defaults

Quinn Dunkan quinn at pyro.ugcs.caltech.edu
Fri Dec 3 22:37:07 EST 1999


I'm trying to set up a system where objects can initialize their attributes
via one of three methods:
explicitly at instantiation:
sphere.texture.pigment = Pigment(color=red)

otherwise via an Xresource-like preferences database:
defaults['Sphere.Texture.Pigment.color'] = red
s = Sphere()

otherwise via the class's default, in its __init__ method.

The tricky bit is the second one, since if a Pigment is initializing itself
it has to figure out that it's the Pigment of a Texture of a Sphere, and
not pick up defaults for Plane.Texture.Pigment.*  What I did was write
a function that works its way up the stack, picking out methods, and then
joins together the __class__.__name__ attrs of the self args of those methods.

This works, but not that well:

Apparently there's no way to figure out if something is a 





More information about the Python-list mailing list