2017-03-23 72 views
0

我被一个特殊的情况困住了,在这里我创建了我的输入文件的纪元时间戳来检查重复项。运行代码后,我得到重复的错误,但实际上没有重复。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 
>>> 

当然,我可以尝试使用不同的代码来获得划时代的时间,但我想知道为什么会出现此问题。

回答

0

当我按原样运行代码时,我在3.5.3和3.6.1中都得到3个不同的时间戳。

2017-03-26 01:55:00 1490507700.0 
2017-03-26 02:55:00 1490511300.0 
2017-03-26 03:55:00 1490514900.0 

当我将日期更改为3-12时,“春天正向”为在美国改变时间日期,我得到分别为3.5和3.6不同的副本。

# 3.5 
2017-03-12 01:55:00 1489301700.0 
2017-03-12 02:55:00 1489301700.0 
2017-03-12 03:55:00 1489305300.0 

# 3.6 
2017-03-12 01:55:00 1489301700.0 
2017-03-12 02:55:00 1489305300.0 
2017-03-12 03:55:00 1489305300.0 

我的结论是a)下一个星期日是你所在国家的“春季前进”日期,b)崇高文本的运行时间为3.5。消除歧义(重复)时间的方法在3.6中进行了修改。查看文档datetime.timestamp。

+0

这些信息对我而言是新闻。我很感谢你分享这个反馈。 –

相关问题