zoukankan      html  css  js  c++  java
  • python利用文件对话框获取文件路径

    一、单文件

    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()

    python2:

    1 import Tkinter, tkFileDialog
    2 
    3 root = Tkinter.Tk()
    4 root.withdraw()
    5 
    6 file_path = tkFileDialog.askopenfilename()

    二、多文件

     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
    '%(float(li[1]),float(li[0])))
    16                 print(li)
  • 相关阅读:
    Flink核心技术
    Flink学习问题和答案
    Spark知识点总结
    Scala知识点总结
    Spark测试题
    Hadoop概念试题
    IntelliJ IDEA 2019 快捷键终极大全
    Linux入门
    javaSe知识点总结
    Data
  • 原文地址:https://www.cnblogs.com/BlackGoat/p/8779608.html
Copyright © 2011-2022 走看看