#
file's name : obj_w_r.py
#
import cPickle as pk
import
pickle as pk
class
Person:
def
__init__
(self, name, age):
self.name
=
name
self.age
=
age
def
sayhi(self):
print
"
Hello everyone, my name is
"
, self.name,
"
, I'm
"
, self.age,
"
years old
"
p
=
Person(
"
nami
"
,
24
)
filename
=
"
c:/nami.data
"
#
save person to nami.data
f
=
file(filename,
"
w
"
)
pk.dump(p, f)
f.close()
#
read person from nami.data
f
=
file(filename)
p
=
pk.load(f)
#
call person's sayhi method
p.sayhi()