python-cloudant 库有一个上下文管理器来简化文档的处理:
# Upon entry into the document context, fetches the document from the # remote database, if it exists. Upon exit from the context, saves the # document to the remote database with changes made within the context. with Document(database, 'julia006') as document: # The document is fetched from the remote database # Changes are made locally document['name'] = 'Julia' document['age'] = 6 # The document is saved to the remote database
来源: http: //python-cloudant.readthedocs.io/en/latest/document.html
如果远程文档不存在,会有什么行为?文档设置为None
,还是抛出异常?