Two minor questions on Class

Peter Otten __peter__ at web.de
Fri Jul 30 13:48:58 EDT 2010


joy99 wrote:
> class Person(object):
> def _init_(self,name,age):
> self.name=name
> self.age=age
>> as i wrote the code using IDLE on WinXP SP2, with Python2.6.5, I am
> getting the following error:
>> >>> p=Person('Subha',40)
>> Traceback (most recent call last):
> File "<pyshell#120>", line 1, in <module>
> p=Person('Subha',40)
> TypeError: object.__new__() takes no parameters
>> My question is, why the error is coming? Any problem in writing it?

The so-called special methods in Python start with two underscores and end 
with two underscores, i. e. the initializer is called
__init__
not
_init_
> If any one can help, I would be grateful. As I pasted the code from
> GUI to notepad, there may be slight indentation problem, sorry for the
> same.
 
It looks fine here.
Peter


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /