references/pointers in Python?

Ignacio Vazquez-Abrams ignacio at openservices.net
Wed Sep 12 12:28:31 EDT 2001


On Wed, 12 Sep 2001, Anton Lavrik wrote:

> Generally, I want to define a referce to an integer, or to the
> identifier, that holds it.
> Python is full of references, is it possible to define it directly? Or
> maybe there are some different ways to do it?

It's true that Python is full of references, but those are references to
instances, not types.

You can do something like the following:

---
class MyVal:
  def __init__(self, val):
    self.set(val)
  def set(self, val):
    self.value=val
  def __call__(self):
    return self.value

a=MyVal(5)
b=a
b.set(3)
print a()
---

-- 
Ignacio Vazquez-Abrams  <ignacio at openservices.net>





More information about the Python-list mailing list