Python class __init__(mandatory arguments?)

Lee John Moore leej at dsl.pipex.com
Mon Jun 16 04:09:51 EDT 2003


One may as well begin with Bengt Richter's letter to comp.lang.python:
>
> On 15 Jun 2003 23:02:26 GMT, Lee John Moore <leej at dsl.pipex.com> wrote:

Firstly, thanks to everybody who responded here.  Secondly, I'll
never post so close to midnight again. ;-)

[..]
>>class MyClass:
>>	param1 = None
>>	param2 = None
>>	def __init__(self, param1, param2):
>>		param1 = self.param1
>>		param2 = self.param2
> You have the 'self.' on the wrong side of the '=' if you
> want to bind the parameters as instance attributes.

Yep.  I just realised this when re-reading the posts.  Of
course, it should've been the other way round.  My
on-the-fly-example was bad and I would've realised if I had at
least tested it first.  :-(

[..]
>>I'm really unhappy that myinstance1 is allowed.  ;-)
> I don't think you actually tried it in the form above ;-)

You're right.  I'm learning by building a command-line router
controller (to bring the WWW link up and down) and using Dive
Into Python (.org) and the python.org tutorial as reference
material.  In my code, I assigned initial values to the
__init__() arguments (eg. def __init__(self, param1=None,
param2=None) - which is what made the arguments optional.  Doh!

Thanks again (I'm sorted now) ;-)
-- 
"However far you may travel in this world, you
will still occupy the same volume of space."
                - Traditional Ur-Bororo saying




More information about the Python-list mailing list