Re: basic Class in Python
"bartc" wrote in message news:xl_4n.28001$ym4.5...@text.news.virginmedia.com... > Any particular reason why two, and not one (or three)? In some fonts it's > difficult to > tell how many as they run together. It follows the C convention for reserved identifers. -- http://mail.python.org/mailman/listinfo/python-list
Re: basic Class in Python
bartc wrote: "Wolfgang Rohdewald" wrote in message news:mailman.1056.1263771299.28905.python-l...@python.org... On Monday 18 January 2010, BarryJOgorman wrote: TypeError: object._new_() takes no parameters def _init_(self, name, job=None, pay=0): __init__ needs two underscores left and right Any particular reason why two, and not one (or three)? In some fonts it's difficult to tell how many as they run together. I believe it was borrowed from C, which has __FILE__ and __LINE__ (CPython is written in C). With hindsight, of course, single underscores would've been sufficient... -- http://mail.python.org/mailman/listinfo/python-list
Re: basic Class in Python
"Wolfgang Rohdewald" wrote in message news:mailman.1056.1263771299.28905.python-l...@python.org... On Monday 18 January 2010, BarryJOgorman wrote: TypeError: object._new_() takes no parameters def _init_(self, name, job=None, pay=0): __init__ needs two underscores left and right Any particular reason why two, and not one (or three)? In some fonts it's difficult to tell how many as they run together. -- Bartc -- http://mail.python.org/mailman/listinfo/python-list
Re: basic Class in Python
On Monday 18 January 2010, BarryJOgorman wrote: > TypeError: object._new_() takes no parameters > def _init_(self, name, job=None, pay=0): __init__ needs two underscores left and right -- Wolfgang -- http://mail.python.org/mailman/listinfo/python-list
Re: basic Class in Python
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
Re: basic Class in Python
On Sun, Jan 17, 2010 at 15:05 -0800, BarryJOgorman wrote: [...] > class Person: > def _init_(self, name, job=None, pay=0): ^^ --> __init__(self, ... It's __init__() not _init_()! Have fun learning Python! -- .''`. Wolodja Wentland : :' : `. `'` 4096R/CAF14EFC `- 081C B7CD FF04 2BA9 94EA 36B2 8B7F 7D30 CAF1 4EFC signature.asc Description: Digital signature -- http://mail.python.org/mailman/listinfo/python-list
Re: basic Class in Python
BarryJOgorman wrote: > 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 In the future, please cut and paste the traceback -- don't retype. You may introduce errors that obscure the actual problem. > #Add incremental self test code > > class Person: > def _init_(self, name, job=None, pay=0): __init__() like all "special" method needs two leading and two trailing underscores, not one. > 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) Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: basic Class in Python
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 -- http://mail.python.org/mailman/listinfo/python-list
basic Class in Python
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