Parsing the results of askopenfilenames()?

前端 未结 4 645
耶瑟儿~
耶瑟儿~ 2020-12-06 06:46

I\'m trying to get a list of filenames from tkinter.filedialog.askopenfilenames() in Python 3.2.

    files = askopenfilenames(initialdir=\"C:\\\\Users\\\\BVC         


        
4条回答
  •  青春惊慌失措
    2020-12-06 06:56

    I just found this question when looking up why I was getting curly brackets instead of a proper list.

    Here's my work around:

    file_list=[]
    files = files = askopenfilenames(initialdir="C:\\Users\\BVCAP\\Videos", title="Select files")
    for file in files:
        file_list.append(file)
    

    I noticed that when I was using the askopenfilenames in my method I never looked at the object returned. I had treated it as a tuple and it worked fine. So knowing it could be iterated in a for loop, it made sense to append each item into a new blank list.

    I hope this helps anyone else who encounters this bug.

提交回复
热议问题