【发布时间】:2014-12-07 14:55:15
【问题描述】:
def God():
set_path()
find_files(path)
def set_path():
'''Sets file path to inputted directory'''
# Should path default to a certain directory if path is invalid?
# (it does here)
#path = Path(input("Enter path\n"))
path = Path(input("Specify a directory:\n")
print("Path set to", path.cwd())
return path
def find_files(path):
'''Stores files in current dir and all subdirs to a list'''
myFiles = []
for element in path.iterdir():
if element.is_dir() == True:
find_files(element)
else:
myFiles.append(element)
print(myFiles)
return myFiles
*** God 函数结合了这两个函数,应该返回设置路径的目录和子目录中所有文件的列表,但是我一直收到此错误消息:
Traceback (most recent call last):
File "<pyshell#11>", line 1, in <module>
God()
File "C:/Users/Project1.py", line 8, in God
return path
NameError: name 'path' is not defined
关于如何返回字符串以供以后在上帝函数和所有后续函数中使用的任何想法?
【问题讨论】:
-
这还能编译吗?您缺少括号。