Save Date and Time File in Python Name

Asked

Viewed 409 times

-1

Friends, I’m new in python and I’m trying to save a file that contains the date and time as the file name.

That’s my code, but it’s not working.

Where am I going wrong?

from datetime import date, datetime

data = datetime.today()
hoje = data.strftime('%d/%m/%Y')
nome = 'Consolidado.xlsx'

...

df.to_excel(f'{hoje}-{nome}', index = False)


2 answers

1

You’re using the bar ("/") in the file name and if you are using Linux, macOS or some UNIX derivative your date will be considered as part of the file path and not its name. And in Windows NTFS the bar is an invalid character to compose file names.

0

Substitute / by another character, for example -.

This is necessary because the one bar means the relative or absolute path of the file.

  • Very good Giovanni. Something so simple. Thank you very much.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.