[Edu-sig] A better way?
urnerk at qwest.net
Mon Nov 8 00:16:16 CET 2004
Just for exercise, one of my students assigned himself the task of making
instance attributes and methods accessible using square brackets instead of
dot notation. This is the best solution I've been able to come up with so
>>> class Test:
self.attr1 = 1
self.attr2 = 2
def method1(self): print "Cough"
def method2(self): print "Chuckle"
def __getitem__(self, value):
>>> otest = Test()
More information about the Edu-sig