Loading just in time

D'Arcy J.M. Cain darcy at druid.net
Thu Jul 10 10:45:30 EDT 2008


I am trying to create a utility module that only loads functions when
they are first called rather than loading everything.  I have a bunch
of files in my utility directory with individual methods and for each I
have lines like this in __init__.py:

def calc_tax(*arg, **name):
    from calc_tax import calc_tax as _func_
    calc_tax = _func_
    return _func_(*arg, **name)

This works the first time I call utility.calc_tax but if I call it
again I get a "TypeError: 'module' object is not callable" error.  Is
there any way to do what I want or do I have to put everything back
into a single file.  Of course, I can simply change all my calls to
utility.calc_tax.calc_tax(...) but I have a lot of code to change if I
do that.

Thanks.

-- 
D'Arcy J.M. Cain <darcy at druid.net>         |  Democracy is three wolves
http://www.druid.net/darcy/                |  and a sheep voting on
+1 416 425 1212     (DoD#0082)    (eNTP)   |  what's for dinner.



More information about the Python-list mailing list