One alrady exists, __slots__. >>> class Foo(object): __slots__ = ['bar', 'baz', 'qig']
>>> f = Foo() >>> f.foo = 'bar' Traceback (most recent call last): File "<pyshell#5>", line 1, in -toplevel- f.foo = 'bar' AttributeError: 'Foo' object has no attribute 'foo' >>> f.bar = 'foo' However, __slots__ only works for class instances, so if you're messing around with uninitialised classes (not a good idea outside the singleton pattern or very functional-style code) it won't work. -- http://mail.python.org/mailman/listinfo/python-list