idiom for initialising variables

Rob Hall bloke at ii.net
Thu Nov 7 06:26:18 EST 2002


Sorry, mistyped the first eg - should have been:

class myClass:
     a = 1
     def __init__(self):
         ...more stuff here

I had ' self ' so firmly entrenched in my mind it just went there
automatically.
When I read code using this method I actually ' read ' self.a event though
there was no self there!

Thanks to all those who pointed out my mistake...  it makes sense now that i
READ it properly!




Rob Hall <bloke at ii.net> wrote in message
news:3dc964fa$0$12989 at echo-01.iinet.net.au...
> I'm just wondering on the correct python idiom for initialising variables.
> I see some code like this:
>
> class myClass:
>     self.a = 1
>     def __init__(self):
>         ...more stuff here
>
>
>
> I also see:
>
> class myClass
>     def __init__(self):
>         self.a = 1
>         ...more stuff here
>
>
> Which is the correct idiom?  or is there a subtle difference I am missing?
>
>
> Rob
>
>





More information about the Python-list mailing list