只有数据结构一要的时候才能传递 ,json用一种通用的类型来传输。
作者归档:aichiao
json
s = ‘{“desc”:”invilad-citykey”,”status”:1002}’
l=”[11,22,33,44]”
import json
result = json.loads(s)
print(result,type(result))
json.loads 用于将字典、列表、元组形式的字符串,转换成相应的字典、列表,元组
所有语言里面双引号肯定是字符串
S 里面如果是字符串类型的,必须是双引号
外面可以用单引号。
user_list=["alex","eric","tomy"]
s = json.dumps(user_list)
print(s,type(s))
path.dirname
print(__file__)
import os
print(os.path.dirname(__file__))
#sys.path python 默认去根据【】的路径去找模块
print(__file__)
import os
import sys
from lib.xx import aaa
print(os.path.dirname(__file__))
sys.path.append(os.path.dirname(__file__) + "/lib/xx")
for i in sys.path:
print(i)
os.path.join
模块
md5
import hashlib
import string
hash1 = hashlib.md5()
hash1.update(bytes("123",encoding = "utf-8"))
h = hash1.hexdigest()
n = int(h,base=16)
print(n)
print(h)
print(hex(n))
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\python.exe “C:\Program Files\JetBrains\PyCharm 2017.2\helpers\pydev\pydevd.py” –multiproc –qt-support=auto –client 127.0.0.1 –port 6131 –file C:/Users/Administrator/PycharmProjects/py/md5test6.py
pydev debugger: process 5276 is connecting
Connected to pydev debugger (build 172.3757.67)
42767516990368493138776584305024125808
202cb962ac59075b964b07152d234b70
0x202cb962ac59075b964b07152d234b70
Process finished with exit code 0
正则表达式之计算器
正则表达式
正则表达式
正则表达式
import re
n = re.findall("(\d+)(\w)*(\d+)","a2b3c45")
m = re.search("(\d+)(\w)*(\d+)","a2b3c45")
print(n)
print(m)
Connected to pydev debugger (build 172.3757.67)
[(‘2’, ‘4’, ‘5’)]
<_sre.SRE_Match object; span=(1, 7), match=’2b3c45′>
Process finished with exit code 0