我有一个给定字符串的位置,如a1 [5]但它随机变化然后如何动态搜索字符串并提取值

时间:2018-01-23 07:25:30

标签: python

import os
import sys
def main():
    pass

if __name__ == '__main__':
    Job_Status = str(sys.argv[1])


a1 = Job_Status.replace("{", "")
a1 = a1.split(',');print a1;

if a1[5] =='runstatus:null':
    print a1[5]

if a1[5] == 'runstatus:203'or a1[5] == 'runstatus:202' or a1[5] == 'runstatus:201' and a1[5] == 'runstatus:null':
    print a1[5]

main()

a1 = ['creationclassname:NVBUPhaseStatus', 'runstarttime:null', 'exitstarttime:1516358894', 'nextruntime:null', 'policyname:null', 'runstatus:null', 'exitbytestransferred:1245184', 'averagesize:1245184', 'runstatusmsg:null', 'serviceid:NVBU-HIPUNL61260', 'jobid:63', 'clientname:AB-WIN2K12R2-64', 'exitstatus:300', 'title:job1', 'jobtype:1', 'ackedstatus:null', 'exitstatusmsg:Backup']
Output : runstatus:null

1 个答案:

答案 0 :(得分:0)

您可以使用index()方法在列表中找到字符串的位置:

pos = a1.index('runstatus:null')