Need clue with import hackery

Richard Jones richard at bizarsoftware.com.au
Thu Aug 2 20:50:40 EDT 2001


On Friday 03 August 2001 10:37, Richard Jones wrote:
> On Friday 03 August 2001 10:08, you wrote:
> > So what I need to know is if there is some way to import the
> > instance_home package as "instance" rather than as "roundup".
>
> This looks like a lost cause (*). It's just plain too icky :(
>
> Oh well.
>
>
>     Richard
>
> * even if I manage to convince the import mechanisms to import /tmp/roundup
> as "instance", there's imports in the /tmp/roundup package "from roundup
> import foo" which are always going to break. Ho hum.

Hey, this is a fun conversation I'm having with myself here :)

The above comment was written because I was doing:

>>> import imp, sys
>>> sys.path.insert(0,'/tmp')
>>> imp.load_module('instance', None, '/tmp/roundup', ('', '', 5))
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "./roundup/templates/classic/__init__.py", line 9, in ?
    from interfaces import *
  File "./roundup/templates/classic/interfaces.py", line 6, in ?
    from roundup import cgi_client, mailgw 
ImportError: cannot import name cgi_client

... but further investigation shows that the "sys.path.insert(0,'/tmp')" is 
not needed...

>>> import imp, sys
>>> imp.load_module('instance', None, '/tmp/roundup', ('', '', 5))
<module 'instance' from '/tmp/roundup/__init__.pyc'>
>>> sys.modules['roundup']
<module 'roundup' from 'roundup/__init__.pyc'>

Yay! :)

Sorry for the noise :)


     Richard




More information about the Python-list mailing list