Pointers

Richard Jones Richard.Jones at fulcrum.com.au
Wed Mar 15 17:59:18 EST 2000


[Curtis Jensen]
> Pointers are sometimes usefull.  I have a module that creates a
> dictionary.  I want to include some elements from the distionary in one
> class and other elements in another class.  If I had pointers, I could
> do that.  Is there another way?

   As I explained in my response to your post (unlike the unhelpful Bjorn ;) 
you're already dealing with a reference there. The dictionary is an object and 
your only control over it is via your reference to it. You can make labels 
(variables) for that reference, or pass that reference around to functions or 
methods. I think you'll find that you can already do what you want:

>>> class A:
...  def foo(self, a):
...   a['A'] = 1
... 
>>> class B:
...  def foo(self, b):
...   b['B'] = 1 
... 
>>> a=A()
>>> b=B()
>>> d={}
>>> a.foo(d)
>>> b.foo(d)
>>> d
{'B': 1, 'A': 1}



        Richard






More information about the Python-list mailing list