码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2018-04-10 16:06:56      阅读:307      评论:0      收藏:0      [点我收藏+]

标签:strip   filedia   dial   line   lines   file_path   技术   分享图片   span   

一、单文件

python3:

技术分享图片
1 import tkinter as tk
2 from tkinter import filedialog
3 
4 root = tk.Tk()
5 root.withdraw()
6 
7 file_path = filedialog.askopenfilename()
View Code

 

python2:

技术分享图片
1 import Tkinter, tkFileDialog
2 
3 root = Tkinter.Tk()
4 root.withdraw()
5 
6 file_path = tkFileDialog.askopenfilename()
View Code

 

二、多文件

技术分享图片
 1 import tkinter as tk
 2 from tkinter import filedialog
 3 
 4 root = tk.Tk()
 5 root.withdraw()
 6 
 7 file_path = filedialog.askopenfilenames()
 8 for f in file_path:
 9     fo = f.split(.)[0]+.csv
10     with open(fo,w) as foo:
11         with open(f,r) as fn:
12             fn.readline()
13             for line in fn.readlines():
14                 li = line.strip().split()
15                 foo.write(%f,%f\n%(float(li[1]),float(li[0])))
16                 print(li)
View Code

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

标签:strip   filedia   dial   line   lines   file_path   技术   分享图片   span   

原文地址:https://www.cnblogs.com/BlackGoat/p/8779608.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!