Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #21789 > unrolled thread
| Started by | Robert Kern <robert.kern@gmail.com> |
|---|---|
| First post | 2012-03-17 01:22 +0000 |
| Last post | 2012-03-17 01:22 +0000 |
| 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.
Re: avoid import short-circuiting Robert Kern <robert.kern@gmail.com> - 2012-03-17 01:22 +0000
| From | Robert Kern <robert.kern@gmail.com> |
|---|---|
| Date | 2012-03-17 01:22 +0000 |
| Subject | Re: avoid import short-circuiting |
| Message-ID | <mailman.745.1331947337.3037.python-list@python.org> |
On 3/16/12 11:14 PM, Andrea Crotti wrote: > Very nice thanks, here it is > class ImportMock: > > def _my_import(self, *args, **kwargs): > self.ls.append(args[0]) > self.orig(*args, **kwargs) There's a bug here. You need to return the module object you got from calling self.orig(). By the way, you really should follow my example of getting the .__name__ from the module object instead of the argument in order to properly account for relative imports inside packages. __import__() will be passed the relative name, not the fully-qualified name. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco
Back to top | Article view | comp.lang.python
csiph-web