±±¾©Ê¯ÓÍ»¯¹¤Ñ§Ôº2026ÄêÑо¿ÉúÕÐÉú½ÓÊÕµ÷¼Á¹«¸æ
²é¿´: 252  |  »Ø¸´: 0

wgx669

ľ³æ (ÕýʽдÊÖ)

[ÇóÖú] Çó´óÉñ°ïæ¿´ÏÂʲôԭÒò²»ÄÜÕý³£ÔËÐÐÄØ £¿

Çó´óÉñ°ïæ¿´ÏÂʲôԭÒò²»ÄÜÕý³£ÔËÐÐÄØ £¿




# 10-8
# database.py

import sys, shelve
def store_person(db):
    """

    Query user for data and store it in the shelf object
    """

    pid = input("Enter unique ID number: "
    person = {}
    person["name"] = input("Enter name:"
    person["age"] = input("Enter age:"
    person["phone"] = input ("Enter phone number:"

    db[pid] = person

def lookup_person(db):
    """
    Query user for ID and desired field, and fetch the the corresponding data from the shelf object
    """

    pid = input("Enter ID number: "
    field = input("What would you like to know?(name\age\phone)"
    field = field.strip().lower()
    print (field.capitalize()+":",\
          db[pid][field] )

def print_help():
    print("The available commands are:"
    print("store: Stores information about a person"
    print("oookup : Looks up a person from ID number"
    print("quit : Save changes and exit"
    print("? : Prints this message"

   
def enter_command():
    cmd = input("Enter command(? for help):"
    cmd = cmd.strip().lower()
    return cmd

def main():
    database = shelve.open("d:\\database.dat"
    try:
        while True:
            cmd = enter_command()
            if cmd == "store":
                store_person(database)
            elif cmd == "lookup":
                lookup_person(database)
            elif cmd == "?":
                print_help()
            elif cmd == "quit":
                return
    finally:
        database.close()

    if _name_ == "_main_": main()

Çó´óÉñ°ïæ¿´ÏÂʲôԭÒò²»ÄÜÕý³£ÔËÐÐÄØ £¿
²¶»ñ.PNG
»Ø¸´´ËÂ¥

» ²ÂÄãϲ»¶

°ÑÎÕ½ñÌ죬ӮµÃÃ÷Ì죡£¡£¡
ÒÑÔÄ   »Ø¸´´ËÂ¥   ¹Ø×¢TA ¸øTA·¢ÏûÏ¢ ËÍTAºì»¨ TAµÄ»ØÌû
Ïà¹Ø°æ¿éÌø×ª ÎÒÒª¶©ÔÄÂ¥Ö÷ wgx669 µÄÖ÷Ìâ¸üÐÂ
×î¾ßÈËÆøÈÈÌûÍÆ¼ö [²é¿´È«²¿] ×÷Õß »Ø/¿´ ×îºó·¢±í
[¿¼ÑÐ] ²ÄÁϵ÷¼Á +6 ÎâèùÓ±£¡ 2026-04-03 6/300 2026-04-03 16:25 by lijunpoly
[¿¼ÑÐ] 266·Ö£¬Çó²ÄÁÏÏà¹Ø×¨Òµµ÷¼Á +13 ÍÛºôºßºôºß 2026-03-30 15/750 2026-04-03 15:24 by arrow8852
[¿¼ÑÐ] 282Çóµ÷¼Á ²»Ìôרҵ ÇóÊÕÁô +7 Yam. 2026-03-30 8/400 2026-04-03 14:12 by zhangdingwa
[¿¼ÑÐ] ÉúÎïѧÇóµ÷¼Á +3 15064154688 2026-04-03 3/150 2026-04-03 10:28 by macy2011
[¿¼ÑÐ] 262Çóµ÷¼Á +6 ÀøÖ¾Ò»¶¨·¢ÎÄÕ 2026-04-02 7/350 2026-04-03 09:54 by linyelide
[¿¼ÑÐ] 0703»¯Ñ§ +7 goldtt 2026-04-02 9/450 2026-04-03 09:36 by À¶ÔÆË¼Óê
[¿¼²©] É격ÇóÖú +3 Reee1Llll 2026-04-01 3/150 2026-04-02 22:29 by ÕâÊÇÒ»¸öÎÞÁĵÄê
[¿¼ÑÐ] ²ÄÁÏר˶322·Ö +10 ¹þ¹þ¹þºðºðºð¹þ 2026-04-02 10/500 2026-04-02 21:46 by dongzh2009
[¿¼ÑÐ] 22408µ÷¼Á +3 EEchoooo 2026-03-27 5/250 2026-04-02 20:19 by EEchoooo
[¿¼ÑÐ] 301Çóµ÷¼Á +4 ϸ°ûÏà¹Øµ°°× 2026-04-02 8/400 2026-04-02 16:30 by 271179835
[¿¼ÑÐ] 303Çóµ÷¼Á +8 DLkz1314. 2026-03-30 8/400 2026-04-02 09:08 by sanrepian
[¿¼ÑÐ] ÉúÎïѧ327£¬Çóµ÷¼Á +5 ÊéÉϵÄ÷×Ó 2026-04-01 6/300 2026-04-02 06:47 by ilovexiaobin
[¿¼ÑÐ] 285Çóµ÷¼Á +11 AZMK 2026-04-01 11/550 2026-04-01 22:40 by peike
[¿¼ÑÐ] ʳƷѧ˶362Çóµ÷¼Á +3 xuanxianxian 2026-04-01 3/150 2026-04-01 21:05 by °¡Àî999
[¿¼ÑÐ] 085601²ÄÁϹ¤³ÌÕÒµ÷¼Á +20 oatmealR 2026-03-29 21/1050 2026-04-01 21:00 by lijunpoly
[¿¼ÑÐ] 332Çóµ÷¼Á +8 Lyy930824@ 2026-03-29 8/400 2026-04-01 18:40 by ǧ¾û³ÎÓñÓî°¡
[¿¼ÑÐ] Ò»Ö¾Ô¸Î÷½»´ó080500²ÄÁÏѧ˶349 +6 jqx1258 2026-03-31 7/350 2026-03-31 21:08 by yuq
[¿¼ÑÐ] 08¹¤¿ÆÇóµ÷¼Á286 +5 tgs_001 2026-03-28 5/250 2026-03-31 08:18 by Ò»Ö»ºÃ¹û×Ó?
[¿¼ÑÐ] 322Çóµ÷¼Á +10 ËÎÃ÷ÐÀ 2026-03-27 10/500 2026-03-30 18:47 by 544594351
[¿¼ÑÐ] Ò»Ö¾Ô¸ÖÐÄÏ´óѧ»¯Ñ§0703×Ü·Ö337Çóµ÷¼Á +6 niko- 2026-03-27 6/300 2026-03-30 10:25 by herarysara
ÐÅÏ¢Ìáʾ
ÇëÌî´¦ÀíÒâ¼û