A simple example of a Python program (communication)

Source: Internet
Author: User
Core code:

The code is as follows:


#!/usr/bin/python
#Filename: friendbook.py
Import Cpickle as P
Import Sys
Import time
Import OS

ab={' xdex ': ' cneds@fnedf.com ',
' laexly ': ' fev@fe.com ',
' FUKC ': ' fexok@ver.com ',
' Stifu ': ' stif@qq.com '
}


def dumpfile (list):
F=file (Friendab, ' W ')
P.dump (LIST,F)
F.close ()


If Os.path.isfile (' Friendab.data '):
friendab= ' Friendab.data '
Else
Os.touch (' Friendab.data ')
DumpFile (AB)
Del AB


F=file (Friendab)
Frilist=p.load (f)


Class Person:
def __init__ (self,name):
Self.name=name
def saysome (self):
print ' The friend%s,his e-mail is%s '% (Sname,frilist[sname])
Class Addperson:
def __init__ (Self,name,email):
Self.name=name
Self.email=email
def addbook (self):
Ab=frilist
Ab[sname]=email
DumpFile (AB)
Del AB
print ' succlessful! '
Class Delperson:
def __init__ (self,name):
Self.name=name
def delbook (self):
Ab=frilist
Ab.pop (sname)
DumpFile (AB)
Del AB
print ' Success DEL '

Class Alterperson:
def __init__ (Self,name,email):
Self.name=name
Self.email=email
def alterbook (self):
Ab=frilist
Ab[sname]=email
DumpFile (AB)
Del AB
print ' Succlessful update! '

print ' \
Prints files to the standard output.
Any number of the files can be specified.
Options include:
[1]: Search your friend ' s email from Friendsbook
[2]: Add your friend ' s email to Firendsbook
[3]: del your friend ' s email from Firnedsbook
[4]: Alter your friend ' s email from Friendsbook
[5]: All friends List
[6]: Exit the program
'''


Num=raw_input (' Press the number [1,2,3,4,5]--')


if (num== ' 1 '):
Sname=raw_input (' Enter the name--> ')
If sname in Frilist:
P=person (sname)
P.saysome ()
Else
print ' Not in it '
Elif (num== ' 2 '):
Sname=raw_input (' Enter the name--> ')
Email=raw_input (' Enter the email--> ')
Pa=addperson (Sname,email)
Pa.addbook ()
#p =person (sname)
#p. Saysome ()
Print Frilist
Elif (num== ' 3 '):
Sname=raw_input (' Enter the name--> ')
Pa=delperson (sname)
Pa.delbook ()
Elif (num== ' 4 '):
Sname=raw_input (' Enter the name--> ')
If sname in Frilist:
Email=raw_input (' Enter the email--> ')
P=alterperson (Sname,email)
P.alterbook ()
Else
print ' Not in it '
Elif (num== ' 5 '):
Print Frilist
Elif (num== ' 6 '):
Print "bye!"
Else
Print "Please input the right number"

Note: This is I wrote the first Python, there are many shortcomings, later improved

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.