Robin Becker <ro...@reportlab.com> writes: > I'm trying to overcome a recursive import issue in reportlab. > ... sketched solution ...
In the "zope" project, the same problem was approached in a slightly different way -- see the product "zope.deferredimport". It allows to defer an actual import for an imported name until this name is accessed. Looking a bit deeper, I recognize that behind the scenes, "zope.deferredimport" uses a technique similar to yours: it replaces the original module by a proxy - which almost behaves like the original module but has the additional capacity to do special things for accessed to names not yet in the modules dictionary. "zope.deferredproxy" is widely used in "zope" projects and I have not seen any related problem report. Looks as its implementation technique is rather safe. You might be able to use "zope.deferredimport" directly for your purposes or look at its implementation to learn what things the implementors have taken care of. Or you might just learn from it, that replacing a module by something similar is quite safe. Dieter -- https://mail.python.org/mailman/listinfo/python-list