繁体   English   中英

Python function 返回无

[英]Python function return is none

我的项目有问题。 在我的程序中,如果需要,我可以选择更多文件。 问题是, return choosen_files有文件列表,但调用 more_files() 方法的 choosen_files 没有。

你有什么建议吗?

这是我的代码

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

非常感谢你!

您不会在最后一行返回任何内容。 只需返回 more_files(files, path)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM