我需要一些帮助。 我正在使用这个方法来帮助我打开一个带有对话框的文件 :
from Tkinter import *
import tkFileDialog
fileOpen = Tk()
fileOpen.withdraw() #hiding tkinter window
file_path = tkFileDialog.askopenfilename(
title="Open file", filetypes=[("txt file",".txt"),("All files",".*")])
if file_path != "":
print "you chose file with path:", file_path
else:
print "you didn t open anything!"
print file_path
It works fine, and the file is opened in Python, but I don t know how to make further commands on that file, for example if I wanted to read it or write on it.
I have tried referencing it as fileOpen, but that doesn t seem to work, and I have no idea what the variable would be instead.