此函数不断抛出名称错误。 我以为它会抛出IO错误什么的。 相反,它告诉我,这个函数没有被定义,而对我来说,它显然是被定义的。
import os
from os import *
def Search_File(self, x):
cur_dir = os.getcwd()
while True:
file_list = os.listdir(cur_dir)
parent_dir = os.path.dirname(cur_dir)
File_Path_Search = x
if File_Path_Search in file_list:
break
if cur_dir == parent_dir:
break
else:
cur_dir = parent_dir
y = Search_File(self, txtFile_Path_Search.text())
错误如下:
Traceback (most recent call last):
File "/home/jacob/Documents/Python Inquiry YES∕NO Program/Inquiry.py", line 68, in Calculate
y = Search_File(self, txtFile_Path_Search.text())
NameError: name 'Search_File' is not defined
你的代码中有很多错误,除非这不是你的完整代码。 是完整的代码还是只是一个片段? 因为你所尝试的是属于一个班级的。 如果它确实属于某个类,请尝试:
self.Search_File(txtFile_Path_Search.text())
如果没有,请提供完整的代码。