【问题标题】:Why does this code work on Linux but not on Windows?为什么这段代码可以在 Linux 上运行,但不能在 Windows 上运行?
【发布时间】:2019-03-05 06:34:24
【问题描述】:

我问过一个关于标记夏令时时间的问题 here。 @MattMessersmith 亲切而专业地回答了我的问题,他的解决方案在 Linux 中完美运行(Ubuntu),但在我的任何一台 Windows 机器上都没有(工作和家庭)。

如果有帮助的话,我的 Windows 机器都在运行带有 Python 3.6 和 pytz 2018.4 的 Anaconda。

当我在 Windows 上运行代码时,我收到以下错误:

Traceback (most recent call last): 
File "<ipython-input-185-ed30519c4311>", line 1, in <module> 
  transition_times = [t.astimezone(tz) for t in transition_times] 
File "<ipython-input-185-ed30519c4311>", line 1, in <listcomp> 
  transition_times = [t.astimezone(tz) for t in transition_times] 
OSError: [Errno 22] Invalid argument

这是在我的 Windows 机器上产生错误的代码:

from pytz import timezone

# Map transition times to year for some efficiency gain                                                                                                                                                     
tz = timezone('America/Denver')
transition_times = tz._utc_transition_times[1:]
transition_times = [t.astimezone(tz) for t in transition_times]

【问题讨论】:

标签: python linux windows python-3.x pytz


【解决方案1】:

这是一个错误:[Windows] datetime.fromtimestamp(t) when 0 <= t <= 86399 fails on Python 3.6

因为tz._utc_transition_times[1:]中的一些datetime object小于1970-01-01 00:00:00.000

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多