简体   繁体   English

Numpy.save text | 将当前日期与特定文件名组合为 txt 标题

[英]Numpy.save text | Combine current date with specific file name as txt title

To store the result of calculations, I save them in txt files using为了存储计算结果,我将它们保存在 txt 文件中

np.savetxt('filename.txt', ..).

What I would like to do is including the current time in the filename so that the file is called "year-month-day filename.txt".我想做的是在文件名中包含当前时间,以便该文件称为“年-月-日文件名.txt”。

I tried to create a string variable and to use the package datetime to get the date in the way I need it.我尝试创建一个字符串变量并使用 package 日期时间以我需要的方式获取日期。 However I was not able to concatenate the date with the specific filename in the np.savetxt() function.但是,我无法将日期与np.savetxt() function 中的特定文件名连接起来。

I am not really familiar yet with numpy so I am looking forward for help!我对 numpy 还不是很熟悉,所以我期待着帮助!

Thank you for advice谢谢你的建议

The solution is simple, try with this:解决方法很简单,试试这个:

from datetime import datetime
import numpy as np

x = y = z = np.arange(0.0,5.0,1.0)
time_now = datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
np.savetxt(time_now+'_project.txt', (x,y,z))

If you want another format only you can modify the strftime parameter, that works for me.如果您只想要其他格式,您可以修改 strftime 参数,这对我有用。 Enjoy your day.祝您愉快。

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

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