vars between classes
Marc Tardif
intmktg at CAM.ORG
Sat May 27 11:10:38 EDT 2000
On Sat, 27 May 2000, Moshe Zadka wrote:
> On Sat, 27 May 2000, Marc Tardif wrote:
>
> > OK, here's working code now. My previous code was only meant to help
> > demonstrate my problem. In this new code, I have tried to change var in
> > the first class by calling "first" explicitly. Unfortunately, "3" is still
> > not printed:
> >
> > #!/usr/local/bin/python
> >
> > class first:
> > def __init__(self, var):
> > self.var = var
> > self.myMethod()
> >
> > def myMethod(self):
> > print "first:", self.var
> > second(self.var)
> ^^^^^^^^^
> Here you construct a new object of class "second", which inherits
> its __init__ from "first", which calls its "myMethod", which prints
> "second." It's still not very clear what you expect to happen.
>
Right. What I would like to happen though is for 'var' to change in
'first' if I change it in 'second'. I could probably set var global, but
since I'm still quite new to Python, I'm wondering if there's a more
proper solution.
More information about the Python-list
mailing list