reference or pointer to some object?

Torsten Mohr tmohr at s.netic.de
Tue Jan 11 01:34:41 EST 2005


Hi,

i'd like to pass a reference or a pointer to an object
to a function.  The function should then change the
object and the changes should be visible in the calling
function.

In perl this would be something like:

sub func {
  $ref = shift;

  $$ref += 123; # change
}

$a = 1;
func(\$a);

is something like this possible in python?

The keyword "global" does NOT fit this purpose to
my understanding as it only makes the variables of
the UPPERMOST level visible, not the ones of ONE
calling level above.

Is this somehow possible with weakref?

I don't want to pass the parameter to a function and
then return a changed value.

Is there some other mechanism in python available to
achieve a behaviour like this?


Thanks for any hints,
Torsten.




More information about the Python-list mailing list