krx
krx

Reputation: 115

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 :

OSError: [Errno 22] Invalid argument:

Upvotes: 0

Views: 432

Answers (1)

Nullman
Nullman

Reputation: 4279

: 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")

Upvotes: 3

Related Questions