[Tutor] Getting class method variable values

Jeff Shannon jeff@ccvcorp.com
Mon Jun 16 19:41:02 2003


Just in case nobody else noticed this, I thought I'd point it out...

Alan Gauld wrote:

>class C:
>     self.d = [...]
>

This can't work,  because at this point in time, 'self' does not exist. 
 This can be done using a class variable (i.e., 'proplist = [...]'), but 
at the time this code is executed (i.e., during startup) there is no 
instace for 'self' to refer to, nor any name 'self' that has been bound 
to any object, instance or otherwise, so it's impossible to set an 
attribute (d) of the 'self' object...

Which just goes to show that everyone, even talented programmers like 
Alan, can sometimes be a bit confused about where we're at in our code, 
which is one of the prime reasons that Python's readability and 
preference for explicitness is such a valuable feature. :)

(This is also a big reason why Extreme Programming style prefers 
pair-programming, so that there's always an extra set of eyes to catch 
things like this.)

Jeff Shannon
Technician/Programmer
Credit International