如何以下列格式获得输出?

时间:2016-01-05 08:07:37

标签: python

import re
import json

def fun(*args):
    loopElem = []

    for stream_line_cmd in args:
        TSUDPSEND=re.search('\w*\d(.*.ts)',stream_line_cmd)
        v1=TSUDPSEND.group(0)
        v1=re.sub(r'[^\w]','_',v1)

        STREAMS_PATH=re.search('\w*.\w*.\w*\d(.*.ts)',stream_line_cmd)
        v2=STREAMS_PATH.group(0)

        DEVICE_UNDER_TEST=re.search('(\s\d.*)(\s\d+)(\s\d+)',stream_line_cmd)
        v3=DEVICE_UNDER_TEST.group(0)

        Temp="tsudpsend '+ STREAMS_PATH +' %s '+ DEVICE_UNDER_TEST + '%s"%(v2,v3)
        # Temp1=Temp.replace('\'','')
        key=v1
        json_object={}
        json_object[key]=Temp
        json_object_data=json.dumps(json_object)
        v4=json_object_data

        loopElem.append(v4)

    db={}
    db['TSUDPSEND']=loopElem

    print "AZ_HLS_PORT_BASED_VOD_TC6_STL_CMD=",db


fun("/home/rebaca/azuki/streams/./tsudpsend/home/rebaca/Automation/Shared/streams/filebased/probStreams/dpkg1.ts 127.0.0.1 500011 2300000","/home/rebaca/azuki/streams/./tsudpsend/home/rebaca/Automation/Shared/streams/filebased/probStreams/sync-seg-1.ts 127.0.0.1 500011 14997222","/home/rebaca/azuki/streams/./tsudpsend/home/rebaca/Automation/Shared/streams/filebased/probStreams/sync-seg-1.ts 127.0.0.1 500011 14997222")

输出获取:

AZ_HLS_PORT_BASED_VOD_TC6_STL_CMD= {'TSUDPSEND': ['{"dpkg1_ts": "tsudpsend \'+ STREAMS_PATH +\' filebased/probStreams/dpkg1.ts \'+ DEVICE_UNDER_TEST + \' 127.0.0.1 500011 2300000"}', '{"1_ts": "tsudpsend \'+ STREAMS_PATH +\' sync-seg-1.ts \'+ DEVICE_UNDER_TEST + \' 127.0.0.1 500011 14997222"}', '{"1_ts": "tsudpsend \'+ STREAMS_PATH +\' sync-seg-1.ts \'+ DEVICE_UNDER_TEST + \' 127.0.0.1 500011 14997222"}']}

预期产出:

AZ_HLS_PORT_BASED_VOD_TC6_STL_CMD= '{"TSUDPSEND": [{"dpkg1_ts": "tsudpsend '+ STREAMS_PATH +' filebased/probStreams/dpkg1.ts '+ DEVICE_UNDER_TEST + ' 127.0.0.1 500011 2300000"}, {"1_ts": "tsudpsend '+ STREAMS_PATH +' sync-seg-1.ts '+ DEVICE_UNDER_TEST + ' 127.0.0.1 500011 14997222"}','{"1_ts": "tsudpsend '+ STREAMS_PATH +' sync-seg-1.ts '+ DEVICE_UNDER_TEST + ' 127.0.0.1 500011 14997222"}]}'

0 个答案:

没有答案