Addressing the last element of a list

Chris Mellon arkanes at gmail.com
Tue Nov 15 04:23:11 EST 2005


On 11/14/05, Bengt Richter <bokr at oz.net> wrote:
> On 14 Nov 2005 11:20:53 GMT, Antoon Pardon <apardon at forel.vub.ac.be> wrote:
>
> >Op 2005-11-14, Paul Rubin schreef <http>:
> >> Antoon Pardon <apardon at forel.vub.ac.be> writes:
> >>> We could then have something like the following.
> >>>
> >>> a = 5
> >>> b = a
> >>> a @= 7
> >>> b ==> would result in 7.
> >>
> >> Ouch!  :-(((
> >>
> >> Can't you live with
> >>
> >> a = [5]
> >> b = a
> >> a[0] = 7
> >>
> >> so b[0] is now 7.
> >
> >And what do I have to do, in case of the following:
> >
> >a = [3, 5]
> >b = a[0]
> >b @= 7
> >a ==> would result in [7, 5]
> >
> >This may seem contrived, but in combination with
> >parameters it could be usefull.
> >
> >Something like:
> >
> >a = [3, 5]
> >
> >def treat(b):
> >  lots of code
> >  b @= new_value
> >
> >f(a[0])
> >a ==> would result in [7, 5]
> >
> >--
> You may be interested in reviewing
>
>     http://groups.google.com/group/comp.lang.python/browse_thread/thread/f96b496b6ef14e2/32d3539e928986b3
>
> before continuing this topic ;-)

I read that thread, and am glad I did before asking like I was going
to, if only to avoid being yelled at for not understanding Python
variables ;)

I understand them, I really do, and I know why they act the way they
do, but I still wanted a reference type for binding GUI objects to
data values - for example, a spinner control to an int value. In C++,
I do it by passing a pointer to an int to the control and letting it
do its thing. Theres no simple obvious way to do the same thing in
Python - I ended up by passing a namespace(any object) and an
attribute (by name) and then setting it via setattr in in the control,
which is non-obvious and icky.

>
> Regards,
> Bengt Richter
> --
> http://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list