我被一个特殊的情况困住了,在这里我创建了我的输入文件的纪元时间戳来检查重复项。运行代码后,我得到重复的错误,但实际上没有重复。Python:与datetime.timestamp |问题日期2017年3月26日,01:55,02:55,03:55
INPUT 1(CSV围栏分隔符文件):在输入1发现
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
重复(从我的代码结果):
(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围栏分隔文件):在输入2发现
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
重复(从我的代码结果):
(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())
更加混乱,崇高的文本2 Python的IDE和IDLE是给2个不同的副本。从崇高文本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]
从空闲输出:
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
>>>
当然,我可以尝试使用不同的代码来获得划时代的时间,但我想知道为什么会出现此问题。
这些信息对我而言是新闻。我很感谢你分享这个反馈。 –