Anonymous attribute/property possible?
Bengt Richter
bokr at oz.net
Fri Mar 8 17:26:05 EST 2002
A class with an anonymous attribute/property would provide a place to put
get/set/del-triggered code.
Use of an object with an anonymous property in an expression
or statement would result in calling the get/set methods defined.
Thus you could write foo(bar) with the effect of foo(bar.__anonymous__)
and bar() with the effect of bar.__anonymous__()
And bar = baz with the effect of bar.__anonymous__ = baz.
But since __anonymous__ could be a property, you could define
methods at will (e.g., get_bar, and set_bar) and write
bar = baz with the effect bar.set_bar(baz) and
foo(bar) with the effect foo(bar.get_bar())
This might work nicely with an interpolated-string class.
E.g.,
is = IS('The get_is anonymous property method will interpolate $variables')
print is # the reference would trigger interpolation with current values
# you could do this now, but you'd have to write "print is.some_property"
If you wanted to access the actual object that had an anonymous property, you'd
have to give it a named method returning self for that purpose.
I think this could open up a whole world of scary delights ;-)
(And ISTM without a backwards compatibility problem).
Regards,
Bengt Richter
More information about the Python-list
mailing list