local_import() nested inside local_import() not working

48 views
Skip to first unread message

John-Kim Murphy

unread,
Dec 9, 2010, 9:47:17 AM12/9/10
to web...@googlegroups.com
I am trying to import a module 'pychimp' from another module 'inbite' using local_import(). Both modules are in my modules directory. When I nest a local_import() inside another local_import() I get an error:
local_import('pychimp', reload=True)
>>> inbite = local_import('inbite', reload=True)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "gluon/compileapp.py", line 241, in <lambda>
  File "gluon/compileapp.py", line 176, in local_import_aux
  File "applications\inbite\modules\inbite.py", line 3, in <module>
NameError: name 'local_import' is not defined

So I try importing the module that has local_import:
import gluon.compileapp
gluon.compileapp.local_import('pychimp', reload=True)
>>> inbite = local_import('inbite', reload=True)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "gluon/compileapp.py", line 241, in <lambda>
  File "gluon/compileapp.py", line 176, in local_import_aux
  File "applications\inbite\modules\inbite.py", line 4, in <module>
AttributeError: 'module' object has no attribute 'local_import'

Unnested, it works fine:
>>> pc = local_import('pychimp', reload=True)

Also if I import like below it also seems to work fine, but I read it is better to import modules from the app modules directory using local_import():
import applications.inbite.modules.pychimp as pychimp

Can anyone tell me how to do nested local_import()?

Thanks,
John

mdipierro

unread,
Dec 9, 2010, 9:51:12 AM12/9/10
to web2py-users
models and controllers are not modules.

models and controllers can import modules using "import <module>" if
<module> is in sys.path and using "local_import(<module>)" if <module>
is not in sys.path but is in /applications/app/modules.

modules are - of course - modules so thy can import other modules
using "import <module>". They should not and cannot use "local_import"
because that's only for models and controllers.

Massimo

On Dec 9, 8:47 am, John-Kim Murphy <left...@gmail.com> wrote:
> I am trying to import a module 'pychimp' from another module 'inbite'
> using local_import(). Both modules are in my modules directory. When I
> nest a local_import() inside another local_import() I get an error:
>
> c...@inbite.py:
> local_import('pychimp', reload=True)
>
> >>> inbite = local_import('inbite', reload=True)
>
> Traceback (most recent call last):
> File "<console>", line 1, in <module>
> File "gluon/compileapp.py", line 241, in <lambda>
> File "gluon/compileapp.py", line 176, in local_import_aux
> File "applications\inbite\modules\inbite.py", line 3, in <module>
> NameError: name 'local_import' is not defined
>
> So I try importing the module that has local_import:
> c...@inbite.py:
Reply all
Reply to author
Forward
0 new messages