import and package confusion

Dale Amon amon at vnl.com
Thu Apr 30 10:09:33 EDT 2009


On Thu, Apr 30, 2009 at 02:38:03AM -0400, Dave Angel wrote:
> As Scott David Daniels says, you have two built-in choices, depending on  
> Python version.  If you can use __import__(), then realize that
>     mod = __import__("WINGTL")
>
> will do an import, using a string as the import name.  I don' t have the  
> experience to know how it deals with packages, but I believe I've heard  
> it does it the same as well.

> One more possibility, if you're only trying to get a single package  
> hierarchy at a time, it might be possible to arrange them in such a way  
> that the sys.path search order gets you the package you want.  Rather  
> than the top level being a package, it'd be an ordinary directory, and  
> you'd add it to the sys.path variable so that when you import a  
> subpackage (which would now really just be a package), you'd get the  
> right one.

That would be too unpredictable. But I find the first option
very interesting. I was looking at the __import__  in the Python 
book and thought it *might* be able to do it, but I was not sure 
if it was a solution or an enticing event horizon.

I'm using 2.5 btw.



-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 196 bytes
Desc: Digital signature
URL: <http://mail.python.org/pipermail/python-list/attachments/20090430/85cebd9c/attachment-0001.sig>


More information about the Python-list mailing list