I was doing a bit of metaprogramming lately and found it to be much easier in Ruby, mainly because the main context in Ruby is an object and I can override its method_missing.
Now, there are several constructs in Python that emulate that behaviour in CLASSES(e.g. with __getattr__()
and then handle it apporpriately), but that does not apply on a global scale.
What I am trying to achieve is something similar to this where the author makes "_" be a valid Ruby script by decoding it into a Ruby function. This of course is easy if you know that every time the interpreter does not know the method, he just falls back into a method you created.
You can emulate this in Python rather easily:
import _
try:
____ _ _____[and so on]
except NameError:
[Handle it]
But this is somewhat clumsy and it would be much easier if you had to just include the module and not do anything else. That would be rather non-pythonic, I know that, but I am curious whether it would be possible without messing with the Python interpreter itself.
Does anyone know of a construct which allows for this behaviour?
Regards, Carson