简体   繁体   中英

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.

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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