DEV Community

Lyner Lim
Lyner Lim

Posted on

Python - datetime as filename

filename = f'{datetime.now():%Y-%m-%d-%H%M}'

with open(f'{filename}.txt', 'w') as file:
    file.write('hello')
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

AWS GenAI LIVE image

Real challenges. Real solutions. Real talk.

From technical discussions to philosophical debates, AWS and AWS Partners examine the impact and evolution of gen AI.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay