Python函数未返回任何值

时间:2018-08-28 03:25:35

标签: python

def ipr_628(a):
    as1=a.split("  ")
    if (as1[0][5:7] == "01"):
        return "m2pa link"
    if (as1[0][5:7] == "02"):
        return "m3ua asp"
import re
arr1=[]
with open ("C:\\Users\\bb0066029\\Desktop\\IPR3.txt","rt") as k:   
    arr=k.read().split("\n")
    arr2=[]
    for j in arr:
        if (re.match("[a-zA-Z|\s]+",j)):
            arr2.append(j.strip())        
    arr3=[]
    arr4=[]
    for l in arr2:       
        if  "0629  SCTP ASSOCIATION TERMINATED" in l or "0628  SCTP ASSOCIATION ESTABLISHED" in l or "0662   SCTP PATH UP" in l :
            str1=(arr2[arr2.index(l)+5])
            print (type(str1))
            print ((ipr_628(str1)))
            t=re.sub("\s+"," ",l)+":"+arr2[arr2.index(l)+5]+":"+str(ipr_628(str1))
            arr3.append(t)
            #arr4.append(arr2[arr2.index(l)+5])
            continue            
    for c in arr3:
        with open("C:\\Users\\bb0066029\\Desktop\\mean.txt","at") as d:
            d.write(c)
            d.write("\n")
            d.close()

当我调用上面的函数时,在主程序中它返回NONE。为什么? 我期望像REPT: COMM 0628 SCTP ASSOCIATION ESTABLISHED CTB08:DATA: 01002A% 000001. 030DED% 000A14% 000A0A% 000A14% 000AEA% 010DED%:m2pa Link

这样的输出

但是我无法用它代替m2pa Link。

1 个答案:

答案 0 :(得分:1)

显然没有一个条件得到满足。如果有要返回的默认值,则可能应该在两个if条件之后添加一个返回值。