[英]Python function return is none
I have a problem in my project.我的项目有问题。 In my program I have the availability to choose more files if I want.
在我的程序中,如果需要,我可以选择更多文件。 The Problem is, that the
return choosen_files
has the list of the files but choosen_files which calls the more_files() method is none.问题是,
return choosen_files
有文件列表,但调用 more_files() 方法的 choosen_files 没有。
Do you have any suggestion?你有什么建议吗?
Here is my code这是我的代码
import tkinter as tk
from tkinter import filedialog as fd
def get_files(path):
root = tk.Tk()
root.withdraw()
files = fd.askopenfilenames(
parent=root, title='Choose all files you want', initialdir=path)
return list(files)
def more_files(choosen_files, path):
print("choosen files:")
[print(file) for file in choosen_files]
wantMoreFiles = input(
"Do you want to choose more files? [(1) yes, (2) no]").lower()
if wantMoreFiles in ['1', 'y', 'yes']:
new_files = get_files(path)
choosen_files.extend(new_files)
more_files(choosen_files, path)
else:
return choosen_files
#this has the correct list
files = ['path/file1']
path = 'path'
choosen_files = more_files(files, path)
#this is none
Thank you very much!非常感谢你!
You don't return anything on the last line.您不会在最后一行返回任何内容。 Just return more_files(files, path)
只需返回 more_files(files, path)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.