Passing arguments to function - (The fundamentals are confusing me)

Gregory Piñero gregpinero at gmail.com
Tue Aug 9 15:18:39 EDT 2005


Thanks everyone.  I understand now.  Everything is a reference, all
that matters is whether I can go inside the "cubbyhole" and change
something.  Immutables don't allow this.

So what if I do want to share a boolean variable like so:
<code>
sharedbool=True
class cls1:pass
cl=cls1()
cl.sharedbool1=sharedbool

sharedbool=False

>>cl.sharedbool1
True   #but I wanted false!
</code>

My guess having read this threat would be to make a simple wrapper
class for a boolean so I'm changing something inside the object
instead of reassigning it?
<code>
class bigbool:
/t def __init__(self,tf):
/t/t self.val=tf
/t def setval(self,tf):
/t/t self.val=tf
</code>
Is there an easier way?


-Greg

On 8/9/05, Rocco Moretti <roccomoretti at hotpop.com> wrote:
> Christopher Subich wrote:
> > Rocco Moretti wrote:
> >
> >> Variables in Python are names. They aren't the cubbyholes into which
> >> you put values, they are sticky notes on the front of the cubby hole.
> >
> >
> > +1 MOTW (Metaphor of the Week)
> 
> Thanks, but please note it's not really mine - I've seen it somewhere
> else before. I thought it was from the website I linked earlier[1], but
> now I'm a little embarrased to find out that isn't, and I have no clue
> where it's from.
> 
> [1] http://starship.python.net/crew/mwh/hacks/objectthink.html 
> --
> http://mail.python.org/mailman/listinfo/python-list 
> 


-- 
Gregory Piñero
Chief Innovation Officer
Blended Technologies
(www.blendedtechnologies.com)



More information about the Python-list mailing list