Skip to content

Commit 1fbd334

Browse files
mimiron8080mimiron8080
authored andcommitted
0716
1 parent 1498b0a commit 1fbd334

File tree

12 files changed

+199
-2
lines changed

12 files changed

+199
-2
lines changed

Class_Contact.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/python
2+
# Filename: Class_Contact.py
3+
4+
import cPickle as p
5+
6+
class Contact:
7+
'''Represent the contact information!'''
8+
def __init__(self, name, phone_number, e_mail):
9+
self.name = name
10+
self.phone_number = phone_number
11+
self.e_mail = e_mail
12+
13+
def GetInfo(self, option):
14+
if option == 'a':
15+
print '''Name: %s \nPhone: %s \nE-mail: %s''' % (self.name, self.phone_number, self.e_mail)
16+
if option == 'p':
17+
print '''Name: %s
18+
Phone: %s''' % (self.name, self.phone_number)
19+
if option == 'e':
20+
print '''Name: %s
21+
E-mail: %s''' % (self.name, self.e_mail)
22+
23+
24+
c = Contact('wanghao','1561896137','[email protected]')
25+
cdic = {'wanghao',c}
26+
f = file('IContact.data', 'w')
27+
p.dump(cdic, f)
28+
f.close()
29+
30+
f = file('IContact.data')
31+
cdic = p.load(f)
32+
for key, value in cdic:
33+
print 'key:%s value:%s' % (key, value)

Class_Contact.pyc

895 Bytes
Binary file not shown.

IContact.data

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
c__builtin__
2+
set
3+
p1
4+
((lp2
5+
S'wanghao'
6+
p3
7+
a(i__main__
8+
Contact
9+
p4
10+
(dp5
11+
S'phone_number'
12+
p6
13+
S'1561896137'
14+
p7
15+
sS'e_mail'
16+
p8
17+
18+
p9
19+
sS'name'
20+
p10
21+
g3
22+
sbatRp11
23+
.

IContact.py

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/usr/bin/python
2+
# Filename: IContact.py
3+
4+
import cPickle as p
5+
import os
6+
7+
_contactListFile = 'IContact.data'
8+
9+
class Contact:
10+
'''Represent the contact information!'''
11+
def __init__(self, name, phone_number, e_mail):
12+
self.name = name
13+
self.phone_number = phone_number
14+
self.e_mail = e_mail
15+
16+
def GetInfo(self, option):
17+
if option == 'a':
18+
print '''Name: %s \nPhone: %s \nE-mail: %s''' % (self.name, self.phone_number, self.e_mail)
19+
if option == 'p':
20+
print '''Name: %s
21+
Phone: %s''' % (self.name, self.phone_number)
22+
if option == 'e':
23+
print '''Name: %s
24+
E-mail: %s''' % (self.name, self.e_mail)
25+
26+
def OpenFile():
27+
if os.path.exists('/Users/air/Desktop/python test/'+ _contactListFile):
28+
f = file(_contactListFile)
29+
print 'suc'
30+
else:
31+
f = file(_contactListFile, 'w')
32+
print 'failed'
33+
contactlist = p.load(f)
34+
f.close()
35+
return contactlist
36+
37+
def SaveFile(contactlist):
38+
f = file(_contactListFile)
39+
p.dump(contactlist, f)
40+
f.close()
41+
42+
def Insert():
43+
name = raw_input('Input name:')
44+
phone = raw_input('Input phonen umber:')
45+
e_mail = raw_input('Input e-mail:')
46+
c = Contact(name, phone, e_mail)
47+
contactlist = OpenFile()
48+
contactlist[name] = c
49+
SaveFile(contactlist)
50+
print 'Insert new contact successfully!'
51+
52+
def Search():
53+
print 'Search is yet completed!'
54+
55+
def Delete():
56+
n = raw_input('Input your name of the contact what you want to delete')
57+
contactlist = OpenFile()
58+
for name, phone, email in contactlist:
59+
if name == n:
60+
del contactlist[name]
61+
SaveFile(contactlist)
62+
print 'Delete is yet completed!'
63+
64+
def main():
65+
option = raw_input('''Please input following option to chose what you want to do:
66+
n- insert new contact
67+
s- search contact
68+
d- delete contact
69+
q- quit\n''')
70+
71+
if option == 'n':
72+
Insert()
73+
elif option == 's':
74+
Search()
75+
elif option == 'd':
76+
Delete()
77+
elif option == 'q':
78+
return
79+
80+
while True:
81+
option = raw_input('''Please chose what to do:
82+
w- Use this system
83+
i- Get Info about this
84+
q- Quit\n''')
85+
if option == 'w':
86+
main()
87+
elif option == 'i':
88+
print '''Bexion co. Ltd 2014.07.15 Version 1.0.0'''
89+
elif option == 'q':
90+
break

IContact.pyc

2.92 KB
Binary file not shown.

args.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@ def powersum(power, *args):
99
print 'i is %s pow(i, power) = %s' % (i,pow(i, power))
1010
return total
1111

12-
def ff(**args):
13-
12+
def ff(power, **args):
13+
'''default '''
14+
for key, value in args.items():
15+
print 'key is %s : value is %s' % (key, value)
1416

1517
print powersum(2, 3, 4)
1618
print powersum(2, 10)
19+
20+
ff(1,i=3,j=4,k=5)

assert.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/python
2+
# Filename: assert.py
3+
4+
mylist = ['item1','item2','item3']
5+
6+
for item in mylist:
7+
print item
8+
i = len(mylist)
9+
while i > 0:
10+
print 'Item is %s' % mylist[i-1]
11+
assert len(mylist) >= 1
12+
print 'POP item is %s' % mylist.pop()
13+
i -= 1
14+
assert len(mylist) >= 1

eval.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/python
2+
# Filename: eval.py
3+
4+
print "eval('2*3') is %d " % eval('2*3')

exec.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/python
2+
# Filename: exec.py
3+
4+
print '''exec 'print "Hello world: How exec work"
5+
6+
is follow:
7+
'''
8+
9+
exec 'print "Hello world: How exec work"'

lambda.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/python
2+
# Filename: lambda.py
3+
4+
def make_repeater(n):
5+
return lambda s: s*n
6+
7+
twice = make_repeater(2)
8+
9+
print twice('word')
10+
print twice(5)

0 commit comments

Comments
 (0)