Starting with Classes - basic problem

Discussion in 'Python' started by barryjogorman, Feb 22, 2010.

  1. 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.
     
    barryjogorman, Feb 22, 2010
    #1
    1. Advertising

  2. barryjogorman

    MRAB Guest

    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_.
     
    MRAB, Feb 22, 2010
    #2
    1. Advertising

  3. On Feb 22, 5:33 pm, Bernard Czenkusz <> 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
     
    barryjogorman, Feb 22, 2010
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jinho
    Replies:
    2
    Views:
    384
    Joseph Millar
    Aug 6, 2003
  2. Michael Gray

    basic classes manipulation

    Michael Gray, Aug 21, 2004, in forum: C++
    Replies:
    4
    Views:
    378
    Howard
    Aug 24, 2004
  3. Engineer
    Replies:
    6
    Views:
    653
    Jeremy Bowers
    May 1, 2005
  4. Replies:
    0
    Views:
    461
  5. Replies:
    1
    Views:
    301
    Laurent Bugnion
    Aug 14, 2006
Loading...

Share This Page