basic Class in Python

2010-01-17 Thread BarryJOgorman
Working through Lutz's 'Learning Python'

Trying to run the following code (from file person.py - see below):

The file is held in Python31.

at the Python31 prompt am entering ''person.py'

Getting the following error:
Traceback (most recent call last)
File "C:python31\person.py", line 9, in (module)
bob=Person('Bob Smith', job='barman', pay =34000)
TypeError: object._new_() takes no parameters




#Add incremental self test code

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

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

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: basic Class in Python

2010-01-17 Thread BarryJOgorman
On Jan 17, 11:09 pm, John Bokma  wrote:
> BarryJOgorman  writes:
> > class Person:
> >     def _init_(self, name, job=None, pay=0):
>
>       def __init__(self, name, job=None, pay=0):
>
> Note 2x _ before and after init.
>
> --
> John Bokma                                                               j3b
>
> Hacking & Hiking in Mexico -  http://johnbokma.com/http://castleamber.com/- 
> Perl & Python Development

Many thanks - onward and upward!
-- 
http://mail.python.org/mailman/listinfo/python-list


Starting with Classes - basic problem

2010-02-22 Thread barryjogorman
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 = 10)
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 
bob = Person('Bob Smith')
TypeError: object.__new__() takes no parameters



All suggestions gratefully received.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Starting with Classes - basic problem

2010-02-22 Thread barryjogorman
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 = 10) 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 
> >    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
-- 
http://mail.python.org/mailman/listinfo/python-list