Hi, I'm looking for a little help with the function "getattr". Here's my code:
class MyClass: def __init__(self): trycmd = getattr(self, "cmd_testing") try: trycmd() except: print "Fail." def cmd_testing(self): print "Victory!" obj = MyClass()
So, when I run this code, I get the output "Fail.". I'm not sure what I'm doing wrong, but as I have tested a little more, I have come to the conclusion that it is not finding the right method (cmd_testing). How can I make this work?
Thanks in advance.
EDIT: My bad, I found out I did a really stupid mistake. I forgot the "None" argument when I set the "trycmd" variable. Problem resolved.