simple class question
Matt Grayson
mgrayson at daedalus.sis.utk.edu
Tue Jan 20 12:51:28 EST 2004
On Jan 20, 2004, at 12:34 PM, C GIllespie wrote:
> Dear all,
>
> I'm new to both python and OOP, so could I ask a simple question.
>
> I have class:
>
> class species:
> __init__(self,pop=0):
> self.pop=pop
> Now I want to do something like this:
>
> X=species(pop=10)
> Y=species(pop=X.pop)
> OK, but now I want to update X.pop and have that mirrored in Y.pop,
> i.e. if
> X.pop=5, Y.pop now equals 5.
>
> What is the best/nicest/simplest way of doing this?
Instead of declaring Y as a new instance of species, just set Y equal
to X:
x = species(pop=10)
y = x
x.pop = 15
print y.pop
>
> Many thanks
>
> Colin
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
------------------------------------------------
Matt Grayson
School of Information Sciences, University of Tennessee
-------------------------------------------------
More information about the Python-list
mailing list