Favorite non-python language trick?

Jp Calderone exarkun at divmod.com
Fri Jul 1 17:48:09 EDT 2005


On Fri, 01 Jul 2005 15:02:10 -0500, Rocco Moretti <roccomoretti at hotpop.com> wrote:
>Joseph Garvin wrote:
>
>> I'm curious -- what is everyone's favorite trick from a non-python
>> language? And -- why isn't it in Python?
>
>I'm not aware of a language that allows it, but recently I've found
>myself wanting the ability to transparently replace objects. For
>example, if you have a transparent wrapper class around a certain
>object, and then determine that you no longer need to wrap the object,
>you can say the magic incantation, and the wrapper instance is replaced
>by what it is wrapping everywhere in the program. Or you have a complex
>math object, and you realize you can reduce it to a simple integer, you
>can substitue the integer for the math object, everywhere.
>
>I mainly look for it in the "object replaces self" form, but I guess you
>could also have it for arbitrary objects, e.g. to wrap a logging object
>around a function, even if you don't have access to all references of
>that function.
>
>Why isn't it in Python? It's completely counter to the conventional
>object semantics.

Smalltalk supports this with the "become" message.  I have also done an implementation of this for Python.

Jp



More information about the Python-list mailing list