Python | Create an empty text file with current date as its name

Python | Create an empty text file with current date as its name

To create an empty text file with the current date as its name, you can use Python's built-in open function in combination with the datetime module. Here's how you can do it:

import datetime # Get the current date in the format YYYY-MM-DD current_date = datetime.datetime.now().strftime('%Y-%m-%d') # Create an empty text file with the current date as its name with open(f"{current_date}.txt", 'w') as file: pass 

This code will create an empty file named YYYY-MM-DD.txt in the current directory, where YYYY-MM-DD is the current date. If you want a different date format, you can adjust the format string passed to the strftime method accordingly.


More Tags

zsh r-plotly tintcolor memory win32com devops variable-declaration pkcs#8 kendo-template angularjs-e2e

More Programming Guides

Other Guides

More Programming Examples