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 ScienceAMITY INTERNATIONAL SCHOOL
PUSHP VIHAR.Department of Computer
Science
2
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)
3
PGT (Computer Science)
DECLARATION
I hereby declare that the project work entitled
“YELLOW PAGES”, submitted toDepartment of Computer Science,
AMITY INTERNATIONAL SCHOOL,PUSHP VIHAR
is prepared by me. All thecoding are result of my personal efforts.
4
DIVYANSHU Class XII D
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 ma’am, 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.
5
Last but not the least, I would like to thank all those who had
helped directly or indirectly towards the completion of this project.
DIVYANHSUClass:
XII D
CONTENTS
1. HEADER FILES USED. . . . . . . . . . . . . . . . . 62. FILES GENERATED. . . . . . . . . . . . . . . . . . .7
3. WORKING DESCRIPTION. . . . . . . . . . . . .8
4. CODING. . . . . . . . . .. . . . . . . . . . . . . . . . .9-135. OUTPUT SCREENS. . . . . . . . . . . . . . . . . .
.14-17
6
6. Glossary. . . . . . . . . . . . . . . . . . . . . . . . . . . .187. BIBLIOGRAPHY. . . . . . . . . . . . . . . . . . . . .19
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.
7
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-file condition, or some other error situation.
FILES GENERATED
DATA FILESADDRESS_BOOK_FILE
PROGRAM FILEYELLOW PAGES.PY
8
EXECUTION FILEYELLOW PAGES .EXE
WORKING DESCRIPTION
This program is designed to keep the friend’srecord.This program consists of six options asfollows
1. TO ADD CONTACT2. TO BROWSE THROUGH
CONTACT3. TO DELETE THE CONTACT4. TO MODIFY THE CONTACT5. TO SEARCH FOR CONTACT6. TO EXIT
9
CODING
def main(): pass
if __name__ == '__main__': main()#!/usr/bin/python#filename address-book.pyimport pickleimport osclass 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 Settings\\admin.PVSR29\\Desktop\\gh\\address_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:
10
list_contacts=[] 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 name\n") # contact_email=raw_input("Enter contact email\n")# contact_phone=raw_input("Enter contact phone number\n")# 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 name\n")
11
address_book_file=open("address_book_file","r") is_file_empty=os.path.getsize("address_book_file")==0 if not is_file_empty: search_name=raw_input("Enter the name\n") 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 deleted\n") 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 deleted\n") 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")
12
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 modified\n") 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 address\n") contact.change_email(new_email) break elif(choice=="2"): new_phone=raw_input("Enter new phone number\n") contact.change_phone(new_phone) break else: print ("Incorrect choice")
13
break 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 choice\n") #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")
14
GLOSSARY
Attribute - Values associated with an individual object. Attributes are accessed using the 'dot syntax': a.x means fetch the x attribute from the 'a' object.
Class - A template for creating user-defined objects. Class definitions normally contain method definitions that operate on instances of the class.
Docstring - A string that appears as the lexically first expression in a module, class definition or function/method definition is assigned as the __doc__ attribute of the object where
20
it is available to documentation tools or the help() builtin function.
Function - A block of code that is invoked by a "calling" program, best used to provide an autonomous service or calculation.
BIBLIOGRAPHY
1 http://www.google.com/
2 http://en.wikipedia.org
3 Computer Science with Python by SumitaArora
4 Object Oriented Programming b
21