首页 > 代码库 > python3的dict
python3的dict
1 dict1 = {getlistUrl:getlistData,getskuUrl:getskuData, approveUrl:approveData, approvedlistUrl:approvedlistData, searchpresellUrl:searchpresellData, deletepresellUrl:deletepresellData}
然后
import collections
info = dict(name=‘cold‘, blog=‘linuxzen.com‘)for key, value in info.items(): print (key, ‘:‘, value)
还学会了,妈蛋,调用函数,蠢哭了 嘤嘤嘤:
def kolApprove(url1, value): kolRequest = requests.post(url=url1,json=value,cookies=userlogin.cookies) print(kolRequest.url) pprint(kolRequest.json()) if kolRequest.status_code == 200: print (kolRequest.status_code,kolRequest.reason,‘\n‘) else: print (kolRequest.read())def main(): print (‘let\‘s try it‘+‘\n‘ ) for ur, va in dict1.items(): kolApprove(ur,va)
# 用main来开始调用main()
后来发现,用dict ,不是顺序请求接口的,于是改成list:
# 搞定了,原来要单独一对的里面才可以用.items()def kolApprove(url1, value): kolRequest = requests.post(url=url1,json=value,cookies=userlogin.cookies) print(kolRequest.url) pprint(kolRequest.json()) if kolRequest.status_code == 200: print (kolRequest.status_code,kolRequest.reason,‘\n‘) else: print (kolRequest.read())def main(): print (‘let\‘s try it‘+‘\n‘ ) for number in list1: for ur, va in number.items(): kolApprove(ur,va)
接着,听说了一个OrderedDict,有序字典,先装utils库,然后:
from collections import OrderedDict‘‘‘这样的形式也行,但是一定要ordereddict来格式化一下numbers列表,不可以先写成dict,再用ordereddict ‘‘‘numbers = ((getlistUrl,getlistData),(getskuUrl,getskuData),(approveUrl,approveData),(approvedlistUrl,approvedlistData),(searchpresellUrl,searchpresellData),(deletepresellUrl,deletepresellData))ordered_dict = OrderedDict(numbers)for k, v in ordered_dict.items(): print (k,v)
不可以直接用numbers={a:b,c:d}这样的字典形式写,
应先写成numbers =((a,b),(c,d))
然后用ordered_numbers = OrderedDict(numbers) 来生成有序化字典,
然后就可以按顺序输出啦,就可以按顺序请求接口啦,啦啦啦啦??
python3的dict
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。