个人--博客访问量
2015-08-21 16:05
267 查看
例子的链接:
http://www.woodpecker.org.cn:9081/doc/abyteofpython_cn/chinese/ch11s06.html
运行起来完全没有问题
但如果把测试那一段改为:
运行的时候就会得到一个异常:
Exception exceptions.AttributeError: "'NoneType' object has no attribute 'popula
tion'" in <bound method Person.__del__ of <__main__.Person instance at 0x00BEC12
0>> ignored
然后改很多次那个变量都有这个异常,好像那个变量只有用swaroop才没有问题,非常怪异。。。。
有没有人知道这是怎么回事?
我用的python版本: Python 2.5.2 windows下面的。
http://www.woodpecker.org.cn:9081/doc/abyteofpython_cn/chinese/ch11s06.html
class Person: '''Represents a person.''' population=0 def __init__(self,name): '''Initializes the person's data.''' self.name=name print '(Initializing %s)' %self.name #When this person is created, he/she adds to the population Person.population+=1 def __del__(self): '''I am dying.''' print '%s says bye.' %self.name Person.population-=1 if Person.population==0: print 'I am the last one.' else: print 'There are still %d people left.' %Person.population def sayHi(self): '''Greeting by the person. Really, that's all it does.''' print 'Hi, my name is %s.' %self.name def howMany(self): '''Prints the current population.''' if Person.population==1: print 'I am the only person here.' else: print 'We have %d persons here.' %Person.population swaroop=Person('Swaroop') swaroop.sayHi() swaroop.howMany() kalam=Person('Abdul Kalam') kalam.sayHi() kalam.howMany() swaroop.sayHi() swaroop.howMany()
运行起来完全没有问题
但如果把测试那一段改为:
test=Person('Swaroop') test.sayHi() test.howMany() kalam=Person('Abdul Kalam') kalam.sayHi() kalam.howMany() test.sayHi() test.howMany()
运行的时候就会得到一个异常:
Exception exceptions.AttributeError: "'NoneType' object has no attribute 'popula
tion'" in <bound method Person.__del__ of <__main__.Person instance at 0x00BEC12
0>> ignored
然后改很多次那个变量都有这个异常,好像那个变量只有用swaroop才没有问题,非常怪异。。。。
有没有人知道这是怎么回事?
我用的python版本: Python 2.5.2 windows下面的。
相关文章推荐
- java继承
- Ubuntu 下对切屏幕的方法
- Redis对象读写序列化
- redhat5.5 安装 nginx1.9.2
- POJ---3321-Apple tree(树状数组)
- 从SASI到SAS:SCSI走过25年
- window.frames
- 科研院所
- HTML 笔记 ---Day01
- oracle中的正则表达式
- Windows环境下Android Studio v1.0安装教程
- 使用升级助 升级了win10,黑屏,无桌面 解决方案
- POJ 3436 ACM Computer Factory(最大流)
- CentOS6.5下RPM方式安装MySQL5.6
- 文件读写操作笔记
- HOJ题目分类
- Windows环境下Android Studio v1.0安装教程
- 有重复元素的排列问题
- TransferResult处理中用MvcHttpHandler在mvc3和mvc5区别
- 开发相关漫谈&技巧&杂项链接汇总