0

帮我

我有 3 列 [empid in integer, flag in integer(1 for in,0 for out) & datetime in string format(ie u'Thu, 03 Oct 2013 17:35:43 +0000)] 我想知道怎么写使用变量计数获取某个日期的 in_time 和 out_time 的代码或算法。这意味着,当计数为偶数时,它会给我 in_time 并且当计数增加时,它会给我 out_time 奇数。这是我尝试过的一些代码。

conn = sqlite3.connect('/home/Documents/attendance_report/data.db')
c = conn.cursor()
c.execute('select * from attendance where emp = 95')
count = 0

for row in c:
   count +=1
   print row
4

1 回答 1

0

您可以使用内置函数enumerate来跟踪索引。

for index, row in enumerate(c):
    if index%2 == 0: # Odd numbered row (since index starts from 0)
        # row contains out_time
        print row
    else:
        # row contains in_time
        print row
于 2013-11-05T19:22:38.260 回答