Python Forum

Full Version: [SOLVED] OSError: [Errno 22] Invalid argument
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Well, there is something in the filename that is not excepted in Windows. I don't remember what the allowed characters for filenames are. Perhaps the colons?

You have to change the datetime format.
For example. I don't use often the datetime module os I had to look ar the documentation
str(datetime.datetime.now().strftime('%Y-%m-%d %Hh%Mm%Ss'))
(Jun-03-2018, 02:39 PM)buran Wrote: [ -> ]the colon is not allowed in file name. Use something like
hdlr = logging.FileHandler('Path to the log file/Logs/log{}.log'.format(datetime.datetime.strftime(datetime.datetime.now(), '%Y%m%d%H%M%S_%f'))
Thank you. This fixed it
I would construct the filename on separate line
log_file = 'Path to the log file/Logs/log{}.log'.format(datetime.datetime.now().strftime('%Y%m%d%H%M%S_%f'))
hdlr = logging.FileHandler(log_file)
You cannot have colon sign as part of file name
Pages: 1 2