学习Python中遇到的问题,求指教!
# -*- coding: UTF-8 -*-
class Person:
'''Represents a person'''
population=0
def _init_(self,name):
self.name=name
print '初始化参数 %s'%self.name
Person.population+=1
def _del_(self):
'''I am dying'''
print '%s says Bye'%self.name
Person.population-=1
if population==0:
print ' I am the last one'
else:
print 'There are still %d people leftl'%Person.population
def sayHi(self):
'''Greeting by the people.
Really,that's all it does.'''
print 'Hi,My name is %s'%self.name
def howMany(self):
'''print the current population'''
if population==1:
print 'I am the only one person here'
else:
print 'We have %d persons here'%Person.population
print '测试开始!'
toby=Person('toby Huang')
toby.sayHi()
toby.howMany()
jimmy=Person('jimmy Huang')
jimmy.sayHi()
jimmy.howMany()
toby.sayHi()
toby.howMany()
>>> import ObjVarTest.py
测试开始!
Traceback (most recent call last):
File "<pyshell#7>", line 1, in <module>
import ObjVarTest.py
File "ObjVarTest.py", line 29, in <module>
toby=Person('toby Huang')
TypeError: this constructor takes no arguments