Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Invalid argument while writing a file

This code works :

f = open('Report\\StatusReport.csv', 'w', newline='')

I need to add timestamp to the filename, something similar to :

time_stamp = time.strftime("%d-%m-%y_%H:%M:%S")
f = open(f'Report\\StatusReport_{time_stamp}.csv', 'w', newline='')

which gives the error :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

OSError: [Errno 22] Invalid argument:

>Solution :

: colons are not legal characters in windows file names

you should change this line

time_stamp = time.strftime("%d-%m-%y_%H:%M:%S")

to something line

time_stamp = time.strftime("%d-%m-%y_%H_%M_%S")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading