changing a var by reference of a list

Jorgen Bodde jorgen.maillist at gmail.com
Tue May 8 09:40:58 EDT 2007


Ok thanks,

I will try this approach. The idea was that I could give a list to the
SQL execute command, so that the results coming back would
automatically be assigned to variables.

With regards,
- Jorgen

On 5/8/07, Diez B. Roggisch <deets at nospam.web.de> wrote:
> Jorgen Bodde wrote:
>
> > Hi,
> >
> > I am trying to simplify my code, and want to automate the assigning of
> > variables I get back from a set. I was thinking of putting the
> > variables I want changed in a list:
> >
> > L = [self._varA, self._varB ]
> >
> > self._varA is a variable I want to change when I pass L to a function.
> > I know doing this;
> >
> > L[0] = 12
> >
> > Will replace the entry self._varA with 12, but is there a way to
> > indirectly change the value of self._varA, through the list, something
> > like a by-reference in C++ or a pointer-pointer?
>
> No, there isn't.
>
> But you could do
>
> L = ['_varA']
>
> for v in L:
>     setattr(self, v, value)
>
> Diez
> --
> http://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list