references / aliases in Python

Jonathan P. jbperez808 at yahoo.com
Tue Jan 14 18:44:53 EST 2003


In:

http://www.python.org/cgi-bin/faqw.py?req=show&file=faq06.031.htp

I couldn't exactly follow Steve Holden's example:

    function(args).dict[index][index].a = 21
    function(args).dict[index][index].b = 42
    function(args).dict[index][index].c = 63

But the idea of references did get through because I was 
trying to do something similar.  I was wondering if there 
was a way to get true references in Python ala below:

>>> class A: 
      def __init__(self):
        self.long_name1=5
        self.long_name2=15
      def f1(self):
        ref1=&self.long_descriptive_name1  # hypothetical address-of operator
        ref2=&self.long_descriptive_name2
        if (*ref1)>(*ref2)+1: (*ref1)=(*ref2) 
        # hypothetical dereference operator

replacing the long and rather unreadable (in practice it often
gets much worse than shown below):
 
      if self.long_descriptive_name1>self.long_descriptive_name2+1: 
          self.long_descriptive_name1=self.long_descriptive_name2

Is there a way to get aliases without having to add a pointer 
type + referencing / dereferencing operators to Python?  What
exactly is the Python philosophy regarding pointer types and 
referencing / dereferencing?




More information about the Python-list mailing list