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


Groups > comp.lang.python > #92904 > unrolled thread

Re: instance as module

Started bydieter <dieter@handshake.de>
First post2015-06-20 08:10 +0200
Last post2015-06-20 08:10 +0200
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#92904 — Re: instance as module

Fromdieter <dieter@handshake.de>
Date2015-06-20 08:10 +0200
SubjectRe: instance as module
Message-ID<mailman.655.1434780646.13271.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web