Get time stamp on a automatic saved text file

I'm currently running some simulations in a python program. When the simulation is done it writes out a text file with some data. Unfortunately, the way this is done is saving the text in the same folder, and with the same name. These are also time consuming simulations, that uses one core of my CPU at the time, which means I can do multiple simulations at a time.

But this also means, that when if I do this, and walk away, and don't come back in time, there will be some overwriting - which is not what I want :)

So my question is (I'm not very good at Python): Can I put a time stamp or something in the end, that would make every file unique somehow, unless they are done at the exact same time ? :)

The code I'm using for creating the text file is:

np.savetxt('/home/user/Desktop/DVH/dvh-%s.txt'%(name.replace("/","-")), dvh1, delimiter=',')

Don't know if any other info is needed.

Thanks in advance.



Use datetime library, taking the current time with the now function and formatting it with the strftime function.

import datetime

time_str ="%Y%m%dT%H%M%S")
file_name_format = '/home/user/Desktop/DVH/dvh-%s_%s.txt'
file_name = file_name_format%(name.replace("/","-"), time_str)
np.savetxt(file_name, dvh1, delimiter=',')

Need Your Help

Swift2 UI Test - Wait for Element to Appear

swift swift2 xcode-ui-testing

I want to have a test pause and wait for an element to appear on screen before proceeding.

ploting 3d graph in matlab?

matlab plot

I am currently a begineer, and i am using matlab to do a data analysis. I have a a text file with data at the first row is formatted as follow: