分类: Python/Ruby
2012-12-27 10:37:30
十三、__del__的使用
有一个特殊的方法__del__,它在对象消逝的时候被调用。对象消
逝即对象不再被使用,它所占用的内存将返回给系统作它用
十四、class的使用
class person:
count = 0
def __init__(self,name,age):
self.name=name
self.age=age
person.count+=1 #用计数的
print'count :%d'%person.count
print'person %s has Initionalized'%self.name
def tell(self):
print 'Name is : %s,Age is :%d'%(self.name,self.age)
class teacher(person):
def __init__(self,name,age,salary):
person.__init__(self, name, age)
self.salary=salary
print 'teacher %s has Initionalized'%self.name
def tell(self):
person.tell(self)
print 'salary is : %d'%self.salary #
class student(person):
def __init__(self,name,age,marks):
person.__init__(self, name, age)
self.marks=marks
print 'student %s has Initionalized'%self.name
def tell(self):
person.tell(self)
print 'marks is : %d'%self.marks
t = teacher('chenlei',12,200)
s = student('wuxiao',10,300)
member=[t,s]
"""将两个对象添加到数组中 """
for me in member:
me.tell()
十五、python中的累加
person.count+=1
十六、pythoon中读取本地文件
从指定的路径读取文件
f = file('D:\soft\README.txt')
# if no mode is specified, 'r'ead mode is assumed by default
while True:
line = f.readline()
if len(line) == 0: # 注意这里要判读文件时候为空的文件
break
print line,
# Notice comma to avoid automatic newline added by Python
f.close() # close the file