python3基础
运维点滴
大家好,我是一枚不断进取的运维攻城狮,分享记录我的笔记~
展开
-
requests返回值cookies转字典
import requestsurl = 'http://www.porters.vip/verify/cookie/index.html'res = requests.get(url=url)print(type(res.cookies))print(res.cookies)cookiesdict = requests.utils.dict_from_cookiejar(res.cookies)print(cookiesdict)结果<class 'requests.cookies原创 2020-11-04 20:22:09 · 328 阅读 · 0 评论 -
每日一技:pip源更换阿里云
更换国内源下载Python库更快:永久更改:pip config set global.index-url https://mirrors.aliyun.com/pypi/simple临时更改:xxxxx就是你要安装的库名pip install xxxxx -i https://mirrors.aliyun.com/pypi/simple原创 2020-11-02 15:21:45 · 207 阅读 · 0 评论 -
python json用法
json.dumps(): 对数据进行编码。json.loads(): 对数据进行解码。# 写入 JSON 数据with open('data.json', 'w') as f: json.dump(data, f) # 读取数据with open('data.json', 'r') as f: data = json.load(f)原创 2020-10-31 11:41:50 · 170 阅读 · 0 评论 -
yield 生成器用法举例
def func(): for i in range(8): yield ig = func()while True: try: print(g.__next__()) except: break说明:for 循环遇到yield会起到暂停效果,直到下一次调用for循环,简单的说就是一次只能取一个数据,可以有效节省内存空间,提高利用率。(不用一直开辟新的内存空间)...原创 2020-10-20 07:37:53 · 88 阅读 · 0 评论