如何使用python打印特定时间间隔的整行

时间:2017-06-07 10:16:34

标签: python-2.7

我需要从用户那里获取starttime和endtime。然后我需要将整行的starttime打印到结束时间。

以下是'xsss.csv'文件中可用的数据

aaaaa lshds aaaaa aaaaa 5:18 ss

dslkd lsh2ds dslkd dslkd 5:19 dd

lshds lshds lshds lshds 5:20 dd

aaaaa aaaaa aaaaa aaaaa 5:21 dase

dslkd dslkd dslkd dslkd 5:22 daew

lshds lshds lshds lshds 5:23 sare

aaaas aaaas aaaas aaaas 5:24 ddd

dslkd dslkd dslkd dslkd 5:25 dss

d hdd d hdd d hdd d hdd 5:26 dfsgdsg

ddddd ddddd ddddd ddddd 5:26 dsdf

wswsx wswsx wswsx wswsx 5:27 dw

swswq swswq swswq swswq 5:28 ff

如果starttime = 5:18并且endtime = 5:20。那么输出应该如下打印

aaaaa lshds aaaaa aaaaa 5:18 ss

dslkd lsh2ds dslkd dslkd 5:19 dd

lshds lshds lshds lshds 5:20 dd

代码段:

导入os,csv,datetime

来自datetime import datetime

starttime = datetime.strptime(raw_input('start time:'),“%H:%M”)

endtime = datetime.strptime(raw_input('end time:'),“%H:%M”)

打印开始时间

打印类型(开始时间)

以open('csvv.csv')为d:

 line =d.readlines()

 print "ell"

 for line in d:

     print  "jjj"    

     if row == starttime and endtime:

         print row

0 个答案:

没有答案