Answer the question
In order to leave comments, you need to log in
How to create files with date in title?
Hello! I'm just learning, please help me solve this problem.
Task:
1) It is necessary to create a list of files of the same type with a name - 'N' and content 'X'
2) When re-creating files, check if there is a file with the name N , if so, rename it to this form - 'old_N_23-12-02' the content should remain 'X'
3) So the file named N should always be the latest one with content 'Y'
Answer the question
In order to leave comments, you need to log in
You can use string or f-string formatting to create the desired name.
strftime for the desired date format.
import datetime
N = "work"
filename = "old_{}_{}.txt".format(N, datetime.date.today().strftime("%d-%m-%y"))
print(filename)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question