0

I get errno 22 with this code:

import datetime
now = str(datetime.datetime.now())
filename = "log_{}".format(now)
logFile = open(filename, "w+")
DanieleManna
  • 23
  • 1
  • 5

1 Answers1

0

Quick fix if you are okay with : being replaced by .:

import datetime
now = str(datetime.datetime.now())
filename = "log_{}".format(now).replace(':', '.')
filename
# 'log_2018-09-13 11.39.42.216000'
logFile = open(filename, "w+")

It is an issue with the filename containing ":" characters.

d_kennetz
  • 5,219
  • 5
  • 21
  • 44
  • thanks! now it works! – DanieleManna Sep 13 '18 at 16:43
  • I the past I've just used `;` it looks about the same, the problem with replacing `:` with `.` is when you go to open the file and delimit the timestamp you can't separate the `.` for microseconds as easily. – tgikal Sep 13 '18 at 16:43