Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #92904

Re: instance as module

From dieter <dieter@handshake.de>
Subject Re: instance as module
Date 2015-06-20 08:10 +0200
References <5583E0EA.2090309@chamonix.reportlab.co.uk>
Newsgroups comp.lang.python
Message-ID <mailman.655.1434780646.13271.python-list@python.org> (permalink)

Show all headers | View raw


Robin Becker <robin@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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: instance as module dieter <dieter@handshake.de> - 2015-06-20 08:10 +0200

csiph-web