有时当我想关闭一个Excel文件时,我得到一个PermissionError:[WinError 32]。为什么?

时间:2017-09-17 07:53:26

标签: python xlsxwriter

有一些向量,我想计算它们之间的相似性。我想将相似性值保存在Excel文件(.xlsx)中。 我正在使用的包是xlsxwriter。 但有时当调用“close()”函数时,会发生错误(但不是每次都发生,这意味着有时程序可以正确执行)。

这是我的代码:

#create a new Excel and a new sheet
sim_order_file = xlsxwriter.Workbook(pre_code + '_' + sim_method + '_' + data_type + '.xlsx')
sim_order_sheet = sim_order_file.add_worksheet()

#write data in the cell
for i in range (len(all_name_sorted)):
    sim_order_sheet.write(i, 0, all_name_sorted[i])

for i in range (len(similarity_value_sorted)):
    sim_order_sheet.write(i, 1, similarity_value_sorted[i])

#close file
sim_order_file.close()

这是错误的描述:

File "D:\python source\predict_software_ND\program_maliang\get_sim_order_xlsx_SVD.py", line 133, in get_sim_order_xlsx_SVD
sim_order_file.close()


File "E:\anaconda\Anaconda3\lib\site-packages\xlsxwriter\workbook.py", line 299, in close
self._store_workbook()


File "E:\anaconda\Anaconda3\lib\site-packages\xlsxwriter\workbook.py", line 627, in _store_workbook
os.remove(os_filename)

PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 
'C:\\Users\\maliang\\AppData\\Local\\Temp\\tmptwf42i2j'

如果有人知道如何解决问题?

0 个答案:

没有答案