from module import * using __import__?

Terry Reedy tjreedy at udel.edu
Sun Jul 3 02:38:22 EDT 2011


On 7/2/2011 12:52 PM, Dan Stromberg wrote:
>
> Is there a decent way of running "from <variable> import *"?  Perhaps
> using __import__?
>
> Does it mean using the copy module or adding an element to globals()
> somehow?
>
> Yes, I think I do have a good use for this: importing either pure python
> or cython versions of a module into a single namespace that can provide
> the same interface (transparent to the caller), whether C extension
> modules are viable in the current interpreter or not.  So you have a
> stub module that provides one or the other, depending on availability
> and suitability.

I suggest you look at some of the Python module that import native code 
implementations when available. heapq for one. maybe functools.




More information about the Python-list mailing list