Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Starting with Classes - basic problem

Reply
Thread Tools

Starting with Classes - basic problem

 
 
barryjogorman
Guest
Posts: n/a
 
      02-22-2010
HAVE THE FOLLOWING VERY BASIC PROGRAM:

class Person:
def _init_(self,name, job=None, pay=0):
self.name=name
self.job=job
self.pay=pay

bob = Person('Bob Smith')
sue = Person('Sue Jones', job='dev', pay = 100000)
print(bob.name, bob.pay)
print(sue.name, sue.pay)

I am getting the following error message:

Traceback (most recent call last):
File "C:/Python31/person1.py", line 7, in <module>
bob = Person('Bob Smith')
TypeError: object.__new__() takes no parameters



All suggestions gratefully received.

 
Reply With Quote
 
 
 
 
MRAB
Guest
Posts: n/a
 
      02-22-2010
barryjogorman wrote:
> HAVE THE FOLLOWING VERY BASIC PROGRAM:
>
> class Person:
> def _init_(self,name, job=None, pay=0):
> self.name=name
> self.job=job
> self.pay=pay
>
> bob = Person('Bob Smith')
> sue = Person('Sue Jones', job='dev', pay = 100000)
> print(bob.name, bob.pay)
> print(sue.name, sue.pay)
>
> I am getting the following error message:
>
> Traceback (most recent call last):
> File "C:/Python31/person1.py", line 7, in <module>
> bob = Person('Bob Smith')
> TypeError: object.__new__() takes no parameters
>
>
>
> All suggestions gratefully received.
>

The special methods use double underscores, not single underscores, eg
__init__ not _init_.
 
Reply With Quote
 
 
 
 
barryjogorman
Guest
Posts: n/a
 
      02-22-2010
On Feb 22, 5:33*pm, Bernard Czenkusz <(E-Mail Removed)> wrote:
> On Mon, 22 Feb 2010 09:26:18 -0800, barryjogorman wrote:
> >HAVE THE FOLLOWING VERY BASIC PROGRAM:

>
> >class Person:
> > * *def _init_(self,name, job=None, pay=0):
> > * * * *self.name=name
> > * * * *self.job=job
> > * * * *self.pay=pay

>
> >bob = Person('Bob Smith')
> >sue = Person('Sue Jones', job='dev', pay = 100000) print(bob.name,
> >bob.pay)
> >print(sue.name, sue.pay)

>
> >I am getting the following error message:

>
> >Traceback (most recent call last):
> > *File "C:/Python31/person1.py", line 7, in <module>
> > * *bob = Person('Bob Smith')
> >TypeError: object.__new__() takes no parameters

>
> >All suggestions gratefully received.

>
> The __init__ method starts and ends with two underscores,not one underscore _init_ as you have used.


thanks
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
3 ESSENTIAL TOOLS FOR STARTING AND MAINTAINING...3 ESSENTIAL TOOLSFOR STARTING AND MAINTAINING...3 ESSENTIAL TOOLS FOR STARTING ANDMAINTAINING... Oanh Bui C++ 0 04-27-2009 12:51 PM
3 ESSENTIAL TOOLS FOR STARTING AND MAINTAINING...3 ESSENTIAL TOOLSFOR STARTING AND MAINTAINING...3 ESSENTIAL TOOLS FOR STARTING ANDMAINTAINING... Oanh Bui C Programming 0 04-27-2009 12:51 PM
3 ESSENTIAL TOOLS FOR STARTING AND MAINTAINING...3 ESSENTIAL TOOLSFOR STARTING AND MAINTAINING...3 ESSENTIAL TOOLS FOR STARTING ANDMAINTAINING... Oanh Bui Python 0 04-27-2009 12:46 PM
Basic advice for starting out =?Utf-8?B?a251Y2tsZTA1?= MCSD 1 04-01-2006 10:44 AM
Upgrading Microsoft Visual Basic 6.0 to Microsoft Visual Basic .NET Jaime MCSD 2 09-20-2003 05:16 AM



Advertisments