Chinaunix首页 | 论坛 | 博客
  • 博客访问: 21038
  • 博文数量: 27
  • 博客积分: 585
  • 博客等级: 中士
  • 技术积分: 270
  • 用 户 组: 普通用户
  • 注册时间: 2012-07-20 17:11
文章分类

全部博文(27)

文章存档

2013年(1)

2012年(26)

我的朋友
最近访客

分类: 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

阅读(198) | 评论(0) | 转发(0) |
0

上一篇:python--part3

下一篇:python--part5

给主人留下些什么吧!~~