开发者

python using iteration to create a single row of values vs many rows of values from CouchDB

I have some code that iterates through 'Documents' in couchDB

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

My result is

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

What I want is

FileName Test1 Duration Test2 Duration Test3 Duration etc...

开发者_JS百科How do I go about doing that?


print fileName, testName, diff,

notice the trailing ,

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜