python利用文件对话框获取文件路径

一、单文件

python3:

 import tkinter as tk
from tkinter import filedialog root = tk.Tk()
root.withdraw() file_path = filedialog.askopenfilename()

python2:

 import Tkinter, tkFileDialog

 root = Tkinter.Tk()
root.withdraw() file_path = tkFileDialog.askopenfilename()

二、多文件

 import tkinter as tk
from tkinter import filedialog root = tk.Tk()
root.withdraw() file_path = filedialog.askopenfilenames()
for f in file_path:
fo = f.split('.')[0]+'.csv'
with open(fo,'w') as foo:
with open(f,'r') as fn:
fn.readline()
for line in fn.readlines():
li = line.strip().split()
foo.write('%f,%f\n'%(float(li[1]),float(li[0])))
print(li)
上一篇:Angular过滤器 自定义及使用方法


下一篇:maven入门(1-2)settings.xml