python 判断时间是否大于6点_python中判断时间间隔的问题
展開全部
代碼有點爛,不過還算能解決問題
注釋比較詳細了#?-*-?coding:?utf-8?-*-
import?datetime
__author__?=?'lpe234'
__date__?=?'2015-04-26'
f?=?file('1.txt')
file_content?=?f.readlines()
all_lines?=?len(file_content)
def?get_(content):
"""
遞歸調用
:param?content:
:return:
"""
#?判斷當前內e69da5e6ba903231313335323631343130323136353331333337383961容行數是否大于2
if?len(content)?>?1:
line_1?=?content[0]
line_2?=?content[1]
#?讀取當前內容的第一行?和?第二行,并分別對比內容是否一致
loc1,?date1,?time1,?type1,?no1?=?line_1.split()
loc2,?date2,?time2,?type2,?no2?=?line_2.split()
#?判斷?除了time?以外的數據是否一致
if?loc1?==?loc2?and?date1?==?date2?and?type1?==?type2?and?no1?==?no2:
#?判斷時間?是否符合要求
if?(datetime.datetime.strptime(time2,?'%H:%M:%S')-datetime.datetime.strptime(time1,?'%H:%M:%S')).seconds\
in?range(4):
#?符合要求,則打印
print?line_1,?line_2.replace('\n',?'')
#?遞歸
return?get_(content[2:])
else:
#?遞歸
return?get_(content[1:])
else:
pass
#?去掉?第一行?:地點????時間????類型????工號
get_(file_content[1:])
輸出結果:C:\Python27\python.exe?D:/00/gui/text/1.py
上海????????2015-04-24?11:25:03????1????123
上海????????2015-04-24?11:25:03????1????123
北京????????2015-04-24?11:25:13????1????127
北京???????2015-04-24?11:25:15????1????127
廣州????????2015-04-24?11:25:16????2????125
廣州????????2015-04-24?11:25:17????2????125
Process?finished?with?exit?code?0
總結
以上是生活随笔為你收集整理的python 判断时间是否大于6点_python中判断时间间隔的问题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux block的含义,Block
- 下一篇: python方法定义..._解析Pyth