vars between classes
DOUGS at oceanic.com
Sat May 27 21:12:26 CEST 2000
[ Marc Tardif followed up with:]
> Thanks, your suggested solution is exactly what I was looking
> for. As you
> hinted, I am still confused about a few basic aspects of oop.
> To make sure
> I understood your example, I have a couple more questions:
> - Do I need to declare "class_var = 0" in first? Everything
> still works as
> expected without it.
No you don't. If you do though, it acts as the default value. I also have
a personal preference for making things explicit in classes and class
variables are confusing enough that I like to see where they fit.
> - Do I need to declare "self.var = var" in __init__? Couldn't
> I simply use
> first.class_var throughout the code?
Yes, if you use 'first.class_var' as the argument to the call to second in
the first.myMethod() definition.
> Thanks for the help,
I don't know if these questions are based on a concrete programming problem
you're trying to solve or just to help your understanding. My experience
(admittedly limited where OO programming is concerned) is that class
variables are extremely rarely needed. Even where I've tried to use them in
prototyping they've never survived into the production code. I'm sure
others experiences are different, and YMMV.
Hope this helps,
More information about the Python-list