FAQ
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.

Search Discussions

  • Bernard Czenkusz at Feb 22, 2010 at 5:33 pm

    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.
  • Barryjogorman at Feb 22, 2010 at 5:46 pm

    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
  • Alex goretoy at Feb 22, 2010 at 5:43 pm
    you need to define init with two underscores, I've made that mistake myself
    long long time ago :)

    def __init__

    not def _init_

    -Alex Goretoy
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: <http://mail.python.org/pipermail/python-list/attachments/20100222/0a1b738e/attachment.html>
  • MRAB at Feb 22, 2010 at 5:45 pm

    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_.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedFeb 22, '10 at 5:26p
activeFeb 22, '10 at 5:46p
posts5
users4
websitepython.org

People

Translate

site design / logo © 2022 Grokbase