我有一个代码来搜索和打开一个文件:
def OpenButton(self, event):
filedialog = wx.FileDialog(self, message = 'Open text file',
defaultDir = '.',
defaultFile = 'TestTOC.txt',
wildcard = "Text source (*.txt)|*.txt|" "All files (*.*)|*.*",
style = wx.OPEN)
if filedialog.ShowModal() == wx.ID_OK:
print filedialog.GetPath()
event.Skip()
它会告诉我文件的路径:C:\....\Desktop\test.txt
我还有另一个代码需要读取我选择的文件:
def ReadButton(self, event):
file=open('C:....\Desktop\test.txt','r') # the same path as above
text=file.read()
file.close()
我如何复制该路径并将其替换为 open(.... , 'r')?