在学习tornado template源码的时候,遇到以下dict.update语法:
def generate(self, **kwargs):
"""Generate this template with the given arguments."""
namespace = {
"escape": escape.xhtml_escape,
"url_escape": escape.url_escape,
"json_encode": escape.json_encode,
"squeeze": escape.squeeze,
"datetime": datetime,
}
namespace.update(kwargs)
对于dict object的update函数做下代码场景和学习笔记:
dic = {"A":"a", "B":"b"}
# print the original dict object, output {"A":"a", "B":"b"}
print dic
# update the given key to invoke the another value if the given key exists
dic.update(A="Aa")
# output {'A': 'Aa', 'B': 'b'}
print dic
# if the the given key is not existed, add this key/value pair in the target dict object
dic.update(C="C")
# output {'A': 'Aa', 'C': 'C', 'B': 'b'}
print dic
;) ! Move on!!!!!
分享到:
相关推荐
例如: ``` # 访问字典中的值 python-dict-方法全文共4页,当前为第1页。 print(my_dict['name']) # 输出:Alice python-dict-方法全文共4页,当前为第1页。 print(my_dict.get('age')) # 输出:25 ``` 如果键不存在...
python库,解压后可用。 资源全名:FilterDict-0.2.1566386417-py3-none-any.whl
资源分类:Python库 所属语言:Python 资源全名:pypinyin-dict-0.2.0.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
资源来自pypi官网。 资源全名:lru-dict-1.1.6.tar.gz
python库,解压后可用。 资源全名:ldict-3.211210.1-py3-none-any.whl
python库,解压后可用。 资源全名:ldict-3.211017.13-py3-none-any.whl
jcseg-1.9.4-src-jar-dict.zip
Linux /usr/share/cracklib/pw_dict.pwd: No such file or directory PWOpen: No such file or directory rpm -ivh /cracklib-dicts-2.8.16-4.el6.i686.rpm passwd #rpm -ivh /dsis/cracklib-dicts-2.8.16-4.el6...
资源分类:Python库 所属语言:Python 资源全名:py-dict-repr-0.1.1.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
资源分类:Python库 所属语言:Python 资源全名:FilterDict-0.2.1552756150-py3-none-any.whl 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
python3.7.4官方文档。Python 3.7.4 is the ...The insertion-order preservation nature of dict objects is now an official part of the Python language spec;Notable performance improvements in many areas.
资源来自pypi官网。 资源全名:dataclass-dict-convert-1.4.2.tar.gz
资源分类:Python库 所属语言:Python 资源全名:dict_to_protobuf-0.0.3.10-py3-none-any.whl 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
langdao-ec-gb.dict.dz
python入门-课后学习-35-拓展__dict__.ev4.rar
CURL是一个利用URL语法在命令行下工作的文件传输工具。...Curl可下载FTP,HTT,HTTP,GOPHE,TELNET,DICT,FILE,LDAP等协议文件,还可以上传HTTP POST,HTTP PUT,FTP uploading,HTTP form based upload,proxies,cookies。
资源来自pypi官网。 资源全名:ldict-3.211210.1-py3-none-any.whl
python库。 资源全名:ldict-3.211017.8.tar.gz