<p>您需要添加一些动态命名级别。我个人使用时间戳。你知道吗</p>
<p>例如,我使用<code>openpyxl</code>来编写excel文件,<code>datetime</code>作为时间戳。你知道吗</p>
<p>通过使用时间戳到秒,你很少会遇到文件名的问题。你知道吗</p>
<p>这是我有数据要写时使用的代码。你知道吗</p>
<pre><code>import os
import openpyxl
from datetime import datetime as dt
list_of_data = [['row1'], ['row2'], ['row3'], ['row4']]
wb = openpyxl.Workbook() # create workbook
main_ws = wb.worksheets[0] # designate what worksheet I am working on.
for sub_list in list_of_data:
main_ws.append(sub_list) # writing data to each row.
# creating timestamp while removing special characters.
time_stamp = ''.join([{'-': '', ' ': '', ':': '', '.': ''}.get(c, c) for c in str(dt.now())])[0:12]
# build file name.
file_name = '{} - {}.xlsx'.format('report', time_stamp)
# using os library to build path to my local documents folder.
path = os.path.join(os.environ['USERPROFILE'], 'Documents', file_name)
# saving wb.
wb.save(filename=path)
</code></pre>
<p>正如你所看到的,我现在有一个excel文件在我的docs文件夹中,有一个时间戳。
<a href="https://i.stack.imgur.com/tWT9h.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tWT9h.png" alt="enter image description here"/></a></p>