【发布时间】:2020-04-14 22:04:10
【问题描述】:
from tkinter.filedialog import askopenfile
root = Tk()
root.geometry('200x100')
def open_file():
file = askopenfile(mode ='r', filetypes =[('Measurement Files', '*.dat')])
if file is not None:
content = file.read()
print(content)
btn = Button(root, text ='Open', command = lambda:open_file())
btn.pack(side = TOP, pady = 10)
mainloop()
Python 3.7 版 代码正在返回文件的内容,但是如何将每列数据保存到不同的变量中?
数据文件结构如图:
我想用每列的数据创建 5 个列表。
【问题讨论】:
-
你应该给我们数据文件的结构,或者最好显示一些示例数据文件。您说的是“数据列”,所以可能是某种 CSV 方言?
-
数据文件为.dat扩展名,由5列数据组成(无标题):
-
700.00000 0.09300 1.05161 320.52990 31.43325 701.00000 0.09277 1.04902 319.74106 31.35589 702.00000 0.09163 1.03608 315.79689 30.96910 703.00000 0.09293 1.05074 320.26695 31.40746 704.00000 0.09583 1.08353 330.25886 32.38733 跨度>
-
每行第五列后是否有换行符? (这在您的示例中没有显示,但在发布评论时可能已被删除)
-
我添加了一张关于数据结构的图片,从每一列我需要创建一个数据列表。
标签: python-3.x variables tkinter import