一个字典通过format()函数转换后就会由dict变为str,
例如:
a = "156464654654" b = "652683126541" c = "{‘username‘:‘%s‘,‘password‘:‘%s‘,‘Submit‘: ‘dre‘}"%(a,b) # c = eval("{‘username‘:‘%s‘,‘password‘:‘%s‘,‘Submit‘: ‘dre‘}"%(a,b)) print(type(c)) #(输出<class ‘str‘>)
所以在用的时候需要再将str转为dict,这里用到的转换为eval(),
例如:
a = "156464654654" b = "652683126541" # c = "{‘username‘:‘%s‘,‘password‘:‘%s‘,‘Submit‘: ‘dre‘}"%(a,b) c = eval("{‘username‘:‘%s‘,‘password‘:‘%s‘,‘Submit‘: ‘dre‘}"%(a,b)) print(type(c)) #(输出<class "dict">)
附上原链接:https://blog.csdn.net/weixin_40894428/article/details/80683137
原文地址:https://www.cnblogs.com/qiaoer1993/p/10843191.html
时间: 2024-10-11 00:02:25