码迷,mamicode.com
首页 > 数据库 > 详细

small db

时间:2016-02-15 21:20:26      阅读:281      评论:0      收藏:0      [点我收藏+]

标签:

 1 #! /usr/bin/env python
 2 #coding=utf-8
 3 import sys,shelve
 4 def store_person(db):
 5     pid=raw_input(Enter unique ID number:)
 6     person={}
 7     person[name]=raw_input(Enter name:)
 8     person[age]=raw_input(Enter age:)
 9     person[phone]=raw_input(Enter phone number:)
10     db[pid]=person#
11 def lookup_person(db):
12     pid=raw_input(Enter ID number:)
13     field=raw_input(What would you like to know?(name,age,phone))
14     field=field.strip().lower()#
15     print field.capitalize()+:,db[pid][field]#
16 def print_help():
17     printThe available commands are:
18     printstore:Stores information about a person
19     printlookup:Looks up a person from ID number
20     printquit:Save changes and exit
21     print?    :Prints this messages
22 def enter_command():
23     cmd=raw_input(Enter command(? for help):)
24     cmd=cmd.strip().lower()
25     return cmd
26 def main():
27     database=shelve.open(C://database.dat)
28     try:
29         while True:
30             cmd=enter_command()
31             if cmd==store:
32                 store_person(database)
33             elif cmd==lookup:
34                 lookup_person(database)
35             elif cmd==?:
36                 print_help()
37             elif cmd==quit:
38                 return
39     finally:
40         database.close()
41 if __name__==__main__:main()

 

small db

标签:

原文地址:http://www.cnblogs.com/laoxuwudi/p/5191306.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!