This document describes a student project on a Yellow Pages application. It includes sections on the header files and files generated for the project, a description of how the application works by allowing users to add, browse, delete, modify and search contacts, coding details for the main application functions, screenshots of the output and interface, a glossary of terms, and bibliography. The project uses Python and Pickle module to serialize contact objects to a file and implement the various contact management functions.
2. 1
A Project Report On
Yellow pages
Submitted By
DIVYANSHU
Class : XII D
Under the Guidance of
Mrs.YASHIKA MALHOTRA
PGT (Computer Science)
Department of Computer Science
AMITY INTERNATIONAL SCHOOL
PUSHP VIHAR.
3. 2
Department of Computer Science
AMITY INTERNATIONAL SCHOOL
PUSHP VIHAR
CERTIFICATE
This is to certify that DIVYANSHU of class XII D has
completed the project YELLOW PAGES during
session 2015-16 under my guidance and supervision.
(Mrs.YASHIKA MALHOTRA)
PGT (Computer Science)
4. 3
DECLARATION
I hereby declare that the project work entitle
d
YELLOW PAGES, submitted to
Department of Computer Science, AMITY
INTERNATIONAL SCHOOL,PUSHP VIHAR
is prepared by me. All the
coding are result of my personal efforts.
DIVYANSHU
Class XII D
5. 4
ACKNOWLEDGEMENT
I would like to express a deep sense of thanks & gratitude to my
project guide Mrs. Yashika Malhotra for guiding me immensely through the
course of the project. He always evinced keen interest in my work. Her
constructive advice & constant motivation have been responsible for the
successful completion of this project.
My sincere thanks goes to Mrs. Ameeta Mohan, Our principal maam, for his
co-ordination in extending every possible support for the completion of
this project.
I also thanks to my parents for their motivation & support. I must
thanks to my classmates for their timely help & support for compilation
of this project.
Last but not the least, I would like to thank all those who had
helped directly or indirectly towards the completion of this project.
DIVYANHSU
8. 7
HEADER FILES USED
1. Import pickle: The pickle module
implements binary protocols for
serializing and de-serializing a Python
object structure.
2. Pickle.load: Read a string from the
open file object file and interpret it as a
pickle data stream, reconstructing and
returning the original object hierarchy.
3. Pickle.dump: Return the pickled
representation of the object as a string,
instead of writing it to a file.
4. EOF Error: This macro is an integer
value that is returned by a number of
narrow stream functions to indicate an
end-of-filecondition, or some other
error situation.
10. 9
WORKING DESCRIPTION
This program is designed to keep the friend
s
record.
This program consists of six options as
follows
1. TO ADD CONTACT
2. TO BROWSE THROUGH CONTACT
3. TO DELETE THE CONTACT
4. TO MODIFY THE CONTACT
5. TO SEARCH FOR CONTACT
6. TO EXIT
11. 10
CODING
def main():
pass
if __name__ == '__main__':
main()
#!/usr/bin/python
#filename address-book.py
import pickle
import os
class Contact:
def __init__(self,name,email,phone):
self.name=name
self.email=email
self.phone=phone
def __str__(self):
return "Name:{0}nEmail
address:{1}nPhone:{2}".format(self.name,self.email,self.phone)
def change_name(self,name):
self.name=name
def change_email(self,email):
self.email=email
def change_phone(self,phone):
self.phone=phone
def add_contact():
address_book_file=open("C:Documents and
Settingsadmin.PVSR29Desktopghaddress_book_file","w")
is_file_empty=os.path.getsize("address_book_file")==0
if not is_file_empty:
list_contacts=pickle.load(address_book_file)
else:
list_contacts=[]
12. 11
try:
contact=get_contact_info_from_user()
address_book_file=open("address_book_file","w")
list_contacts.append(contact)
pickle.dump(list_contacts,address_book_file)
print ("Contact added")
except KeyboardInterrupt:
print ("Contact not added")
except EOFError:
print ("Contact not added")
finally:
address_book_file.close()
def get_contact_info_from_user():
try:
contact_name=raw_input("Enter contact namen") #
contact_email=raw_input("Enter contact emailn")#
contact_phone=raw_input("Enter contact phone numbern")#
contact=Contact(contact_name,contact_email,contact_phone)
return contact
except EOFError as e:
#print "You entered end of file. Contact not added"
raise e
except KeyboardInterrupt as e:
#print "Keyboard interrupt. Contact not added"
raise e
def display_contacts():
address_book_file=open("address_book_file","r")
is_file_empty=os.path.getsize("address_book_file")==0
if not is_file_empty:
list_contacts=pickle.load(address_book_file)
for each_contact in list_contacts:
print (each_contact)
else:
print ("No contacts in address book")
return
address_book_file.close()
def search_contact():
#search_name=input("Enter the namen")
address_book_file=open("address_book_file","r")
13. 12
is_file_empty=os.path.getsize("address_book_file")==0
if not is_file_empty:
search_name=raw_input("Enter the namen")
is_contact_found=False
list_contacts=pickle.load(address_book_file)
for each_contact in list_contacts:
contact_name=each_contact.name
search_name=search_name.lower()
contact_name=contact_name.lower()
if(contact_name==search_name):
print (each_contact)
is_contact_found=True
break
if not is_contact_found:
print ("No contact found with the provided search name")
else:
print ("Address book empty. No contact to search")
address_book_file.close()
def delete_contact():
#name=input("Enter the name to be deletedn")
address_book_file=open("address_book_file","r")
is_file_empty=os.path.getsize("address_book_file")==0
if not is_file_empty:
name=raw_input("Enter the name to be deletedn")
list_contacts=pickle.load(address_book_file)
is_contact_deleted=False
for i in range(0,len(list_contacts)):
each_contact=list_contacts[i]
if each_contact.name==name:
del list_contacts[i]
is_contact_deleted=True
print ("Contact deleted")
address_book_file=open("address_book_file","w")
if(len(list_contacts)==0):
address_book_file.write("")
else:
pickle.dump(list_contacts,address_book_file)
break
if not is_contact_deleted:
print ("No contact with this name found")
14. 13
else:
print ("Address book empty. No contact to delete")
address_book_file.close()
def modify_contact():
address_book_file=open("address_book_file","r")
is_file_empty=os.path.getsize("address_book_file")==0
if not is_file_empty:
name=raw_input("Enter the name of the contact to be modifiedn")
list_contacts=pickle.load(address_book_file)
is_contact_modified=False
for each_contact in list_contacts:
if each_contact.name==name:
do_modification(each_contact)
address_book_file=open("address_book_file","w")
pickle.dump(list_contacts,address_book_file)
is_contact_modified=True
print ("Contact modified")
break
if not is_contact_modified:
print ("No contact with this name found")
else:
print ("Address book empty. No contact to delete")
address_book_file.close()
def do_modification(contact):
try:
while True:
print ("Enter 1 to modify email and 2 to modify address and 3 to quit
without modifying")
choice=raw_input()
if(choice=="1"):
new_email=raw_input("Enter new email addressn")
contact.change_email(new_email)
break
elif(choice=="2"):
new_phone=raw_input("Enter new phone numbern")
contact.change_phone(new_phone)
break
else:
print ("Incorrect choice")
break
15. 14
except EOFError:
print ("EOF Error occurred")
except KeyboardInterrupt:
print ("KeyboardInterrupt occurred")
print ("Enter 'a' to add a contact, 'b' to browse through contacts, 'd' to delete a contact,
'm' to modify a contact, 's' to search for contact and 'q' to quit")
while True:
choice=raw_input("Enter your choicen") #gh
if choice == 'q':
break
elif(choice=='a'):
add_contact()
elif(choice=='b'):
display_contacts()
elif(choice=='d'):
delete_contact()
elif(choice=='m'):
modify_contact()
elif(choice=='s'):
search_contact()
else:
print ("Incorrect choice. Need to enter the choice again")
20. 19
GLOSSARY
Attribute - Values associated with an
individual object. Attributesare accessed using
the 'dot syntax': a.x means fetch the x attribute
from the 'a' object.
Class - A templatefor creatinguser-defined
objects. Class definitionsnormallycontain
method definitionsthat operateon instances of
the class.
Docstring - A string that appears as the
lexicallyfirst expression in a module, class
definition or function/method definition is
assigned as the __doc__attributeof the object
where it is availableto documentationtools or
the help() builtin function.
Function - A block of code that is invoked by a
"calling"program, best used to provide an
autonomousservice or calculation.