简体   繁体   English

将数据从多个文本文件保存到单个文件

[英]Saving data from multiple text files to a single file

I was trying to open multiple files using tkinter . 我试图使用tkinter打开多个文件。 I want to see the contents in these multiple files and put these text files to a single file but on different cells, so that i can treat all the data together. 我想查看这些多个文件中的内容,并将这些文本文件放到一个文件中,但放在不同的单元格中,以便可以将所有数据一起处理。 I was not able to find ant tutorial to understand more about tkinter. 我找不到蚂蚁教程来了解有关tkinter的更多信息。 Can anyone suggest me an idea on how to see the contents in these files? 谁能建议我有关如何查看这些文件中内容的想法?

I have an idea on how to do this on matlab, can anyone suggest a way to do the same in python? 我对如何在matlab上执行此操作有一个想法,有人可以建议在python中执行相同操作的方法吗?

Matlab code: Matlab代码:

[filename,pathname] = uigetfile('*.txt','MultiSelect','on');
data = cell(1)

Python code: Python代码:

import tkinter as tk
from tkinter import filedialog

root = tk.Tk()
filez = filedialog.askopenfilenames(parent=root,title='Choose a file')
print (root.tk.splitlist(filez))

Example of how you might do it. 您可能如何做的例子。 If your files ar bigger you might want to use ScrolledText instead. 如果文件较大,则可能要使用ScrolledText。 I have not included buttons or logic or laying out of more than two files side by side, or how to combine them. 我没有包含按钮或逻辑,也没有并排放置两个以上的文件,也没有如何组合它们。 But then again, your question was kind of broad. 但是话又说回来,您的问题有点笼统。

import tkinter as tk
from tkinter import filedialog

# Some test data
text = """lid,loan_amount,currency,sector
653051,300.0,Changed,Food
53,575.0,PKR,Trns
653068,150.0,INR,Trns
653063,200.0,PKR,Arts
653084,400.0,PKR,Food
653067,200.0,INR,Agri
653078,400.0,PKR,Serv
653082,475.0,PKR,Manu
653048,625.0,PKR,Food"""

root = tk.Tk()
main = tk.Frame(root, padx=10, pady=10)
root.resizable(width=False, height=False)
main.pack()

text1 = tk.Text(main, width=40, height=20, padx=10, pady=5)
text1.pack(side='left')
text2 = tk.Text(main, width=40, height=20, padx=10, pady=5)
text2.pack(side='left', padx=(10,0))

# Put filedialog and open files here

text1.insert('end', text)
text2.insert('end', text)

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

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