标签:转换 mon eve 回顾 返回 range seve 知识 mpi
#这里数字转换主要是为了解决网站返回虚假数据的问题,但写完才发现网站的数字是有自己的一套机制的,而不是固定的,因此不好解决,那就当回顾一下re匹配知识吧。
str="1332-31-15"
# print(str[:-5])
# print(str1[:-5])
import re
# print(A)
# print(type(A))
def trans(A):
num=[]
for i in range (0,len(A)):
if A[i]=="0":
zero=re.compile("0")
z=re.sub(zero,"5",A[i])
num.append(z)
elif A[i]=="1":
one=re.compile("1")
o=re.sub(one,"2",A[i])
# print(o,i)
num.append(o)
elif A[i]=="2":
two=re.compile("2")
t=re.sub(two,"9",A[i])
# print(t,i)
num.append(t)
elif A[i]=="3":
three=re.compile("3")
t2=re.sub(three,"0",A[i])
# print(t2,i)
num.append(t2)
elif A[i]=="4":
four=re.compile("4")
f=re.sub(four,"6",A[i])
# print(f,i)
num.append(f)
elif A[i]=="5":
five=re.compile("5")
f2=re.sub(five,"4",A[i])
# print(f2,i)
num.append(f2)
elif A[i]=="6":
six=re.compile("6")
s=re.sub(six,"7",A[i])
# print(s,i)
num.append(s)
elif A[i]=="7":
seven=re.compile("7")
s2=re.sub(seven,"3",A[i])
# print(s2,i)
num.append(s2)
elif A[i]=="8":
eight=re.compile("8")
e=re.sub(eight,"1",A[i])
# print(e,i)
num.append(e)
elif A[i]=="9":
nine=re.compile("9")
n=re.sub(nine,"8",A[i])
# print(n,i)
num.append(n)
# print(num)
number=‘‘.join(num)
return number
year=str[:4]
y=trans(year)
mon=str[5:7]
m=trans(mon)
day=str[8:10]
d=trans(day)
print(y+‘-‘+m+‘-‘+d)
标签:转换 mon eve 回顾 返回 range seve 知识 mpi
原文地址:https://www.cnblogs.com/lvjing/p/9584537.html