How to concatenate the timestamp on a file in python3.
this is working: This does not have timestamp defined
self.write_report(failed_users, "users_ldap_report.txt")
This is not working: I am trying to add timestamp in the file for tracking so want to use REPORT_TIME
to be used.
import time
REPORT_TIME = time.strftime("%Y%m%d%H%M%S")
self.write_report(failed_users, "users_ldap_report REPORT_TIME.txt")
Note: failed_users
is just a list .
Please guide.
CodePudding user response:
You can try the following code,
import time
REPORT_TIME = time.strftime("%Y%m%d%H%M%S")
self.write_report(failed_users, "users_ldap_report {}.txt".format(REPORT_TIME))