reference or pointer to some object?

Steven Bethard steven.bethard at gmail.com
Wed Jan 12 17:31:13 EST 2005


Torsten Mohr wrote:
> I still wonder why a concept like "references" was not
> implemented in Python.  I think it is (even if small)
> an overhead to wrap an object in a list or a dictionary.
> 
> Isn't it possible to extend Python in a way to use
> real references?  Or isn't that regarded as necessary?

IMHO it's not really necessary.  As long as you're passing a mutable 
object around, when you call one of its methods, the object will be 
changed.  So the only time you'd want a "reference" is if you were 
passing around an immutable object (e.g. an int, float, str or tuple) 
and you wanted to change it.  The thought of changing an immutable 
object seems kind of silly to me. ;)

Could you give us a more concrete use case?  My suspicion is that 
anything complicated enough to be passed to a method to be modified will 
probably be more than a simple int, float, str or tuple...  In which 
case, it will probably have methods to allow you to update it...

In my case, rather than your original example, which you want to look 
something like:

     def func(x):
         x += 123

     x = 5
     func(x)

I'd just write:

     x = 5
     x += 123

=)

Steve



More information about the Python-list mailing list