So I have a XLS file that is being accessed via the xlutils library. When my program is finished doing its process, its supposed to delete the original file and rename the temporary file to the original file. The data in the excel file is being input a website and data from the website is being extracted and then written to the excel sheet. All this is fine, however, when its done its having an issue renaming the temp file.
The temp file is simply a copy made via the following function:
def rename(self, fpath):
tempf=os.path.splitext(fpath)[0]
tempf=tempf + "-output" + ".xls"
shutil.copyfile(fpath,tempf)
return tempf
I have created a function which is called when the for loop for inputting data and extracting is finished:
def allDone(self, event):
dlg = wx.MessageBox("All done!", "Ask Alfred", wx.OK | wx.ICON_INFORMATION)
os.unlink(self.fpath)
os.rename(self.temp, self.fpath)
Using Process Explorer, it shows that the temp file is still open in python.exe. I don't know how to close the file and free memory since it is being opened by using:
rbook=open_workbook(file)
sheet = rbook.sheet_by_index(0)
where file will simply be replaced with whatever self.temp is.
When a GO button is pushed the following happens:
def onGo(self, event):
fpath=self.pathBox
fpath=fpath.GetValue()
self.fpath=fpath
temp=myClass.rename(fpath)
self.temp=temp
openFile(temp)
def rename(self, fpath):
tempf=os.path.splitext(fpath)[0]
tempf=tempf + ".alf"
shutil.copyfile(fpath,tempf)
return tempf
So the name of the file which is in a SearchCtrl called "pathBox" is obtained and a temp copy is made and then renamed.