again i am struggling with something alth开发者_如何学Goough it might be a little simpler to fix unlike the binary arrays with my last post. Basically, I created a timer object with a function name. Yet, I keep getting a problem because it says that the function that i call is not defined under Name Error.
class DrawBot():
waitingt = Timer(30.0, lockmap)
...
def onlockmap(self, user):
self.onBackup(user, "lockmapbackup")
waitingt.start()
def lockmap():
onrestoremap("lockmapbackup")
NameError: name 'lockmap' is not defined
Because it's not defined until you get to the actual definition. Plus, you probably don't want to have a single timer shared across every instance of the class... try this instead:
class DrawBot():
def __init__(self):
self.waitingt = Timer(30.0, self.lockmap)
...
def onlockmap(self, user):
self.onBackup(user, "lockmapbackup")
self.waitingt.start()
def lockmap(self):
onrestoremap("lockmapbackup")
lockmap()
is part of DrawBot()
, so if you were to call it by itself, you'd get a NameError
.
Try calling it by using self
, which references the class
:
waitingt = Timer(30.0, self.lockmap)
精彩评论