[Ironpython-users] How to use __ getattr__ to the current module?
Niels Poppe
niels at netbox.org
Wed Sep 19 06:09:10 CEST 2012
# 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