Home > Net >  Add date time variable to results files
Add date time variable to results files

Time:01-28

I am starting out in Python.

I am doin a quality control analysis of data and I am looking for a function that adds the date and time to the figures/tables/data that comes out of the jupyter notebook.

I found the datetime Python package and I wanted to ask how to use it to add a date variable to these outputs.

As an example, this is the line to store an adata object in a file:

adata.write(data_dir 'data_filtered.h5ad')

Any ideas on how I could add a date variable to it so that if I repeat it tomorrow I can distinguish the different analysis?

As I mentioned, I am starting out so I would appreciate your help a lot.

Edit

I would like to add the date to the file name and in the case of tables and figures add in them as well.

CodePudding user response:

Add the date(time) in the name of the file, replace :

adata.write(data_dir   'data_filtered.h5ad')

by

import datetime as dt
current_date = dt.date.today()
current_date_str = current_date.isoformat()

filename = data_dir   'data_filtered_'   current_date_str   '.h5ad'
adata.write(filename)
  • Related