[Edu-sig] a question on java attributes vs. python

Leif Johnson leif@ambient.2y.net
Wed, 30 Apr 2003 03:55:02 -0400


On Tue, 29 Apr 2003, Kirby Urner wrote:

> Your static instances variable is being overridden by your instantiated
> version of instances when you write self.instances += 1.  Every new object
> will see instances = 0 at the class level, then add 1 to it, referring
> to its own self's dictionary.
> 
> If you want "group access" to class-level instances for all objects of
> type MyObject, then your increment statement should read:
> MyObject.instances += 1.

Oops ! Thanks for the correction. : ) Wrote too quickly, yet again. I wasn't
aware of the staticmethod() function either, but that's excellent.

> I've yet to comprehend OO in Scheme.  It seems to be an "advanced topic" in
> that language, whereas in Python "everything is an object" so it makes sense
> to start thinking in OO terms fairly early.

Even if you don't consciously start out thinking in OO terms, even, I've found
that it's easy to nudge myself in the OO direction as needed. I'm especially a
fan of being able to use functions like objects (and vice versa). The apply()
function is great. Python has made the procedural -> OO transition much easier
than, e.g. C would have made it.

leif

--
Leif Morgan Johnson . http://ambient.2y.net/leif/
IAESTE trainee      . http://www.iaeste.org/
Salomon Automation  . http://www.salomon.at/