Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python名称错误-在同一类中调用以前定义的函数时_Python_Python 3.x_Function_Class_Methods - Fatal编程技术网

Python名称错误-在同一类中调用以前定义的函数时

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

我需要帮助解决这个错误。 我创建了一个类,其中包含不同的函数。我的目标是调用基于特定事件触发而创建的类的某些函数。 当我的事件被触发时,我得到一个错误,称为Name error

我将代码包括在下面:

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

中未定义。谢谢,我修复了我的代码,现在它正在工作。