I have a code to search and open a file :
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()
and it will show me the path of the file : C:\....\Desktop\test.txt
And i have another code that need to read the file that i have chose :
def ReadButton(self, event):
file=open('C:....\Desktop\test.txt','r') # the same path as above
text=file.read()
file.close()
How can i copy that path and substitute it into open(…. , ‘r’)?
Use a variable?