所以这段代码最初是一个函数,在我的帮助下,我把它分成了两个独立的函数,但我仍然在努力让它工作。任何指导都将不胜感激
# -------------------------------------------
# Checks to see if listed folders exists and then deletes
# -------------------------------------------
def check_directory(path):
# returns true if path is an existing directory
return os.path.exists(path) and os.path.isdir(path)
dirs_to_delete = [
'C:\Folder Here',
'C:\Folder Here1',
'C:\Folder Here2',
'C:\Folder Here3'
]
def remove_directory(pathlist):
for path in pathlist:
if check_directory(path):
shutil.rmtree(path)
print(colored('Found ' + path + ' removing', 'green'))
我调用这个函数
remove_directory() #Checks and Removes directories listed above
运行时出现以下错误
remove_directory() #Checks and Removes directories listed above
TypeError: remove_directory() missing 1 required positional argument: 'pathlist'
在您的帖子中,似乎您正在调用
remove_directory
,但没有按要求传递列表,将呼叫改为
remove_directory()
至remove_directory(dirs_to_delete)
您需要将
dirs_to_delete
传递给函数:remove_directory(dirs_to_delete)
您已经定义了
remove_directory
来获取单个位置参数pathlist
,但是,它在全局范围内不获取变量pathlist
的值:所以对于你的问题,你需要通过arg
相关问题 更多 >
编程相关推荐