Missing Something Simple

John Abel jabel at plus.net
Tue Jul 12 11:09:24 EDT 2005


harold fellermann wrote:

>
>so, if I understand you right, what you want to have is a list of
>mutable objects, whose value you can change without changing the 
>objects'
>references.
>  
>
Yes!

>class Proxy :
>	def __init__(self,val) : self.set(val)
>	def set(self,val) : self.val = val
>	def get(self) : return self.val
>
>
>a = Proxy(1)
>b = Proxy(2)
>c = Proxy(3)
>
>varList = [a,b,c]
>
>for i in varList :
>	i.set(returnVarFromFunction())
>
>print a,b,c
>
>prints whatever returnVarFromFunction has returned.
>n.b.: instead of the Proxy class, you can use any other mutable
>objects, e.g. lists.
>
>
>- harold -
>
>
>--
>"All unsere Erfindungen sind nichts als verbesserte Mittel
>  zu einem nicht verbesserten Zweck."
>-- H.D. Thoreau
>
>  
>
That does it.  Thank you! 

J



More information about the Python-list mailing list