תיאור
סקריפט פשוט (מאוד) המשתמש במודול shelve על מנת ליצור קובץ ובו מידע המחולק למפתחות וערכים (כמו מילון בפיתון). אני השתמשתי בו כספר טלפונים, אך ניתן להשתמש בו לכל דבר הדורש סידור מידע בצורה זו. כמובן שניתן גם להוסיף מקומות לערכים נוספים (דף בית, כתובת מגורים, תאריך לידה וכו') בעזרת שינויים קלים בקוד.
אני רוצה לציין שאת הסקריפט הזה כתבתי כחודש אחרי שהתחלתי ללמוד פיתון. בקרוב אני מתכוון להוציא גירסה חדשה ומשופרת,בעלת אפשרויות רבות אחרות ובתקווה שגם GUI.
הסקריפט
1 #This program was made by Mark Kels,
2 #If you have any thing to say to me, email me at Mark.Kels@gmail.com .
3 #
4 #This is a simple Adrees book that was made using the shelve module.
5 #The book is a Dictionarie and the Name is the key of the details (ICQ,Phone,etc).
6 #this is the first version,soon there will be another one with more options.
7
8 import shelve
9 book=shelve.open("Address book")
10
11 #The opening function:
12 def start():
13 #Print the options
14 print
15 print "1.View name"
16 print "2.Add/Edit name"
17 print "3.Delete name"
18 print "4.Exit"
19 print
20 #Get input
21 choice=raw_input(">> ")
22 #If choice is 1, get Name and use it as a key in the book Dictionarie
23 if choice=="1":
24 viewname=raw_input("Name: ")
25 print book[viewname]
26 start()
27 #If choice is 2, get Name(key) and details(values),then add is all to the book Dictionarie
28 elif choice=="2":
29 addname=raw_input("Name: ")
30 addphone=raw_input("Phone number: ")
31 addicq=raw_input("ICQ number: ")
32 addemail=raw_input("Email: ")
33 book[addname]=("Phone: "+addphone,"ICQ: "+addicq,"Email: "+addemail)
34 start()
35 #If choice is 3, get name and delete it from the book Dictionarie
36 elif choice=="3":
37 delname=raw_input("Name: ")
38 del book[delname]
39 start()
40 #If choice is 4 do nothing(=program ends)
41
42
43 start()
דיון