[Ironpython-users] How to use __ getattr__ to the current module?

sepatan at sibmail.com sepatan at sibmail.com
Wed Sep 19 07:24:52 CEST 2012


Hello, Niels Poppe.
 Thank you. This is a good option. Once again, thank you)))).


> # didn’t test any of this in IronPython
> # this may work and/or help you further
> # read on about eval, exec and execfile builtins at
> #
> http://docs.python.org/library/functions.html?highlight=execfile#execfile
>
> class GenericFunction(object):
>     __slots__ = ('__name',)
>     def __init__(self, name):
>         self.__name = name
>     def __call__(self, *args, **kwargs):
>         print "called %s(args=%r, kwargs=%r)" % (self.__name, args,
> kwargs)
>
> class Locals(dict):
>     def __getitem__(self, key):
>         if not key in self:
>             self[key] = GenericFunction(key)
>         return super(Locals, self).__getitem__(key)
>
> exec("""tt(3, yy=4)""", globals(), Locals())
>
>
> # python -i test.py
> called tt(args=(3,), kwargs={'yy': 4})
>
>
>
>



More information about the Ironpython-users mailing list