python使用迭代来创建单行值与来自CouchDB的多行值

时间:2011-03-22 17:11:12

标签: python couchdb

我有一些代码可以遍历couchDB中的“Documents”

for docid in db:
    test = db.get(docid)
    try:
        type = test['type']
    except:
        type = "dontTestMe"

    if type == 'file':
        fileName = test['AliasName']
        fileID = test['fileid']
        testName = None

    if type == 'job':
        testName = test['testname']
        stStart = time.strptime(time.ctime(test['teststart']))
        stStop = time.strptime(time.ctime(test['testfinish']))
        difStart = datetime.datetime(stStart.tm_year, stStart.tm_mon, stStart.tm_mday, stStart.tm_hour, stStart.tm_min, stStart.tm_sec)
        difStop = datetime.datetime(stStop.tm_year, stStop.tm_mon, stStop.tm_mday, stStop.tm_hour, stStop.tm_min, stStop.tm_sec)
        diff = difStop - difStart

    print fileName, testName, diff

我的结果是

Filename Test1 DurationOfTest
Filename Test2 DurationOfTest
Filename Test3 DurationOfTest
etc...

我想要的是

FileName Test1 Duration Test2 Duration Test3 Duration etc...

我该怎么做?

1 个答案:

答案 0 :(得分:2)

print fileName, testName, diff,

注意尾随