简体   繁体   English

如何在文件名中使用变量

[英]How to use a variable in filename

I am trying to use the current date & time as a file name for my spreadsheet file but I keep on getting the error "no such file or directory exists." 我正在尝试使用当前日期和时间作为电子表格文件的文件名,但我不断收到错误消息“不存在此类文件或目录”。 Below is the code that I tried to use: 以下是我尝试使用的代码:

wb = Workbook()
dest_filename = time.strftime("%d/%m/%Y_%H:%M.xlsx")
wb.save(filename = dest_filename)

Look at your file name: 查看您的文件名:

time.strftime("%d/%m/%Y_%H:%M.xlsx")

When this statement is executed it returns a result like this: 执行此语句时,它返回如下结果:

'10/06/2015_11:44.xlsx'

Do you have a directory structure that looks like this: 您是否具有如下所示的目录结构:

/PathToScript
   /10
      /06
          2015_11:44.xlsx

Those / s in the file name are indicating directories. 那些/在文件名s的显示目录。 If you wish to have a DMY pattern, I suggest using something other than a / as a separator: 如果您希望使用DMY模式,建议您使用/以外的其他字符作为分隔符:

time.strftime("%d-%m-%Y_%H:%M.xlsx")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM