Python名称错误-在同一类中调用以前定义的函数时
我需要帮助解决这个错误。 我创建了一个类,其中包含不同的函数。我的目标是调用基于特定事件触发而创建的类的某些函数。 当我的事件被触发时,我得到一个错误,称为Name error 我将代码包括在下面:Python名称错误-在同一类中调用以前定义的函数时,python,python-3.x,function,class,methods,Python,Python 3.x,Function,Class,Methods,我需要帮助解决这个错误。 我创建了一个类,其中包含不同的函数。我的目标是调用基于特定事件触发而创建的类的某些函数。 当我的事件被触发时,我得到一个错误,称为Name error 我将代码包括在下面: class OurHandler(FileSystemEventHandler): # def __init__(self, source): # self.source = source def move_epub(self): for i in
class OurHandler(FileSystemEventHandler):
# def __init__(self, source):
# self.source = source
def move_epub(self):
for i in os.listdir(self.source):
print("Hello World")
def on_any_event(self, event):
print(f"\n\n{self}\t\t {event}\n\n")
move_epub()
track_this_folder = "pathname"
a = OurHandler()
observer = Observer()
observer.schedule(a, track_this_folder)
observer.start()
try:
while True:
time.sleep(10)
except KeyboardInterrupt:
observer.stop()
observer.join()
move\u epub
是一个函数,因此需要调用self.move\u epub()
另外,您将遇到的下一个问题是
self.source
在move\u epub
中未定义。谢谢,我修复了我的代码,现在它正在工作。