Hi to all…here is the code for address book in python
#!usr/bin/python
import sys
import MySQLdb
conn=MySQLdb.connect(host="localhost",user="root",passwd="password",db="balaji")
cursor=conn.cursor()
cursor.execute("create table if not exists users (name varchar(20),address varchar(50),email varchar(30),mobile varchar(12))")
def printt():
ch=int (raw_input("1.Add New 2.Search 3.Exit \n Enter Your Choice"))
while(ch!=4):
if(ch==1):
name=raw_input("Enter a Name")
address=raw_input("Enter address")
email=raw_input("enter Email address")
mobile=raw_input("enter mobile no.")
cursor.execute("""insert into users (name,address,email,mobile) values (%s,%s,%s,%s)""",(name,address,email,mobile))
option=raw_input("Add Another Record y/n")
if(option=='y'):
ch=1
else:
printt()
if(ch==2):
name1=raw_input("Enter a name to Search")
cursor.execute("""select * from users where name=(%s)""",(name1))
result=cursor.fetchall()
for row in result:
name=row[0]
address=row[1]
email=row[2]
mobile=row[3]
print " name=%s \n address=%s \n email=%s \n mobile=%s" % (name,address,email,mobile)
option=raw_input("Search Another Name (y/n)")
if(option=='y'):
ch=2
else:
printt()
if(ch==3):
sys.exit()
printt()