这里我们可以看到产生潦攀类型转换 (type conversion). 如不雅欲望值是一个 list, 我们可以经由过程对 string 调用 str.split(',') 来获得我们想要的值。 对于 int, 我们可以简单地应用参数为 string 的 int() 即可。 对于字符串与 str() 也是同样的事理。
Command Handlers
下面是敕令处理器 (command handler) 的代码. 它们都十分直不雅,易于懂得。 留意到固然有很多的缺点检查, 然则也并不是面面俱到, 十分复杂。 在你浏览的过程中,如不雅发明有任何缺点请移步 这里 进行评论辩论.
- def update_stats(command, success):
- """Update the STATS dict with info about if executing *command* was a
- *success*"""
- if success:
- STATS[command]['success'] += 1
- else:
- STATS[command]['error'] += 1
- def handle_put(key, value):
- """Return a tuple containing True and the message to send back to the
- client."""
- DATA[key] = value
- return (True, 'key [{}] set to [{}]'.format(key, value))
- def handle_get(key):
- """Return a tuple containing True if the key exists and the message to send
- back to the client"""
- if key not in DATA:
- return (False, 'Error: Key [{}] not found'.format(key))
- else:
- return
推荐阅读
交通银行信息技术管理部副总经理张漫丽:交通银行“大数据+人工智能”应用研究
大年夜数据隐含着巨大年夜的社会、经济、科研价值,已引起了各行各业的高度看重。如不雅能经由过程人工智能技巧有效地组织和应用大年夜数据,将对社会经济和科学研究成长产生巨大年夜的推>>>详细阅读
本文标题:用Python写一个NoSQL数据库
地址:http://www.17bianji.com/lsqh/35303.html
1/2 1