【发布时间】:2019-12-17 23:05:59
【问题描述】:
我有一个函数可以从用户在我的 Tkinter GUI 窗口中选择的两个单独的目录(文件夹)中检索文件列表。两个目录中所有文件的列表都可以在 Visual Studio 代码终端中打印,但是如何从这两个目录中获取文件列表以打印到新的文本文件?
Input_1 = entry_field1.get() #Retrieving what the user inputed into entry field 1.
Input_2 = entry_field2.get() #Retrieving what the user inputed into entry field 2.
file_list_1=os.listdir(Input_1) #Listing the files from directory 1.
file_list_2=os.listdir(Input_2) #Listing the files from directory 2.
print (file_list_1) #Printing the files in the terminal window.
print (file_list_2) #Printing the files in the terminal window.
【问题讨论】:
-
您问的是如何将数据写入文件的基本问题吗?数据的来源无关紧要。许多 python 教程都介绍了写入文件。
-
这能回答你的问题吗? Writing a list to a file with Python
-
正确。我想将数据写入文件。
标签: python python-3.x user-interface tkinter