在windows计算机上使用Python 3:
我有一个函数,可以获取列表列表,并使用我的默认应用程序(excel)将其作为csv文件打开。尽管在写入后关闭了文件,但当excel启动时,我会收到一条“锁定编辑”的消息。在def opencsv(data):
"""saves a list of lists as a csv and opens"""
import tempfile
import os
import csv
handle, fn = tempfile.mkstemp(suffix='.csv')
with open(fn,"w", encoding='utf8',errors='surrogateescape',\
newline='') as f:
writer=csv.writer(f)
for row in data:
try:
writer.writerow(row)
except Exception as e:
print ('Error in writing row:',e)
f.close()
url = 'file://' + fn.replace(os.path.sep, '/')
os.startfile(fn)
opencsv([['d1','d2'],['d3','d4','d5']])
我怎么能解决这个问题?在