data strucutures in python
Kragen Sitaker
kragen at dnaco.net
Tue Sep 19 23:41:03 EDT 2000
In article <8q8s7c$2ic6$1 at nntp6.u.washington.edu>,
Donn Cave <donn at u.washington.edu> wrote:
>So what
>you want, in these terms, is a namespace where you can intervene in
>the assignment of names.
>
> . . .
>the __setattr__() method. Now we're talking more like
>
> self.lambda = 10 --> self.ChangeLambdaFunc(10)
>
>If that will work for you, there's hope. It's awfully unusual, though -
>I was going to say look at the distribution library for examples, but
>in all those 137 or so modules I don't see a single use of __setattr__.
>It's not terribly easy to use, either - remember, it applies to the
>whole namespace.
I was chatting with a coworker about this today. He mentioned that C#
has a neat way of declaring active properties --- you say something
like:
class foo {
property lambda {
int get() { code here }
void set() { code here }
};
};
and then the code in the get and set "methods" will be invoked to
implement reading or writing the property "lambda" of any object of the
class "foo".
I understand Sather, SELF, Smalltalk, and Delphi all have this
ability. It sounds like that's what the OP was asking for.
In Perl and Python, you have to use __setattr__ (or, I think, AUTOLOAD)
to handle all the properties at once. Perhaps that's why this ability
is not used much here <wink>
language-lawyering-ly y'rs - kragen
--
<kragen at pobox.com> Kragen Sitaker <http://www.pobox.com/~kragen/>
Perilous to all of us are the devices of an art deeper than we ourselves
possess.
-- Gandalf the Grey [J.R.R. Tolkien, "Lord of the Rings"]
More information about the Python-list
mailing list