【问题标题】:Python OSErrror errno22 when creating a file [duplicate]创建文件时的Python OSError errno22 [重复]
【发布时间】:2019-02-18 10:47:15
【问题描述】:

我用这个代码得到 errno 22:

import datetime
now = str(datetime.datetime.now())
filename = "log_{}".format(now)
logFile = open(filename, "w+")

【问题讨论】:

标签: python exception


【解决方案1】:

如果您对 : 被 . 替换没问题,请快速修复:

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

文件名中包含“:”字符的问题。

【讨论】:

  • 谢谢!现在可以了!
  • 我过去我刚刚使用; 看起来差不多,用. 替换: 的问题是当你去打开文件并分隔时间戳时你可以不要轻易地将. 分开几微秒。
猜你喜欢
  • 2016-02-22
  • 2021-10-10
  • 2018-12-10
  • 2012-09-21
  • 2012-10-07
  • 2018-08-09
  • 1970-01-01
  • 2020-11-17
  • 1970-01-01
相关资源
最近更新 更多