【发布时间】:2017-03-23 13:08:45
【问题描述】:
我被一个特殊的情况难住了,我正在为我的输入文件创建纪元时间戳以检查重复项。运行代码后,我得到重复的错误,虽然实际上没有重复。
INPUT 1(带围栏分隔符的 CSV 文件):
1:55|The Chris Ramsey Show|||3/26/2017
2:25|South Park|The Biggest Douche in the Universe|615|3/26/2017
2:55|South Park|My Future Self 'n' Me|616|3/26/2017
在 INPUT 1 中发现重复项(来自我的代码):
(i.e., programs with the same start time and date):
(1490489700, '01:55', 'The Chris Ramsey Show', '', '03/26/2017')
(1490489700, '02:55', 'South Park', "My Future Self 'n' Me", '03/26/2017')
INPUT 2(带围栏分隔符的 CSV 文件):
3/26/2017|2:55|The Chris Ramsey Show|30|||103|Episode 3
3/26/2017|3:25|South Park|30|||615|The Biggest Douche in the Universe
3/26/2017|3:55|South Park|20|||616|My Future Self n' Me
在 INPUT 2 中发现重复项(来自我的代码):
(i.e., programs with the same start time and date):
(1490493300, '02:55', 'The Chris Ramsey Show', 'Episode 3', '03/26/2017')
(1490493300, '03:55', 'South Park', "My Future Self n' Me", '03/26/2017')
在调试时,我发现 3 个不同的时间段导致了这个问题。
03/26/2017 01:55
03/26/2017 02:55
03/26/2017 03:55
我尝试直接在 Python 中复制此问题,因此创建了以下代码:
import datetime
t1 = datetime.datetime(2017, 3, 26, 1, 55)
t2 = datetime.datetime(2017, 3, 26, 2, 55)
t3 = datetime.datetime(2017, 3, 26, 3, 55)
print(t1, t1.timestamp())
print(t2, t2.timestamp())
print(t3, t3.timestamp())
更令人困惑的是,Sublime Text 2 Python IDE 和 IDLE 给出了 2 个不同的重复项。
Sublime Text 2 IDE 的输出:
2017-03-26 01:55:00 1490489700.0
2017-03-26 02:55:00 1490489700.0
2017-03-26 03:55:00 1490493300.0
[Finished in 0.1s]
IDLE 的输出:
Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 07:18:10) [MSC v.1900 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>>
================== RESTART: C:\Users\<>\Desktop\test.py ==================
2017-03-26 01:55:00 1490489700.0
2017-03-26 02:55:00 1490493300.0
2017-03-26 03:55:00 1490493300.0
>>>
当然,我可以尝试使用不同的代码来获取纪元时间,但我想知道为什么会出现这个问题。
【问题讨论】:
标签: python-3.x sublimetext2 python-idle