references / aliases in Python follow-up

Jonathan P. jbperez808 at yahoo.com
Wed Jan 15 01:17:30 CET 2003


>    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?

Actually I believe my C++ is quite rusty and the example above 
may not reflect C++ usage... I don't think there is a need to 
apply the dereference operator after all.

So:

  def f1(self):
    ref1=&self.long_descriptive_name1
    ref2=&(self.long_descriptive_name2) # alternative syntax
    if ref1>ref2+1: ref1=ref2  # self.long_descriptive_name1 gets assigned to

works in the hypothetical scenario.  Or one could always do:

    ref1=aliasof(self.long_descriptive_name1)

Seems clean enough at first glance, but the python gurus here
might be able to point out pitfalls.




More information about the Python-list mailing list