G
Guest
I'd like to be able to look up a method name by passing a string with
the method name. I thought I could use self.__dict__ to get at the
method names, but as my example shows, this is obviously not working.
I've also tried self.__class__.__dict__ without success.
Can anyone point me in the right direction to make this work?
Thanks,
Phil
def m1(self):
print 'm1'
def __getitem__(self, k):
return self.__dict__[k]
def m2(self):
print 'm2'
File "<pyshell#56>", line 1, in ?
z['m1']
File "<pyshell#51>", line 5, in __getitem__
return self.__dict__[k]
KeyError: 'm1'
the method name. I thought I could use self.__dict__ to get at the
method names, but as my example shows, this is obviously not working.
I've also tried self.__class__.__dict__ without success.
Can anyone point me in the right direction to make this work?
Thanks,
Phil
def m1(self):
print 'm1'
def __getitem__(self, k):
return self.__dict__[k]
def m2(self):
print 'm2'
Traceback (most recent call last):z=b()
dir(z) ['__doc__', '__getitem__', '__module__', 'm1', 'm2']
z['m1']
File "<pyshell#56>", line 1, in ?
z['m1']
File "<pyshell#51>", line 5, in __getitem__
return self.__dict__[k]
KeyError: 'm1'