usage of __import__ across two files

Diez B. Roggisch deetsNOSPAM at web.de
Mon Dec 13 13:05:30 CET 2004


>         tb = __import__('BMTest2')

This yields the _module_ BMTest2 in the variable tb. Now in that module
there is a class BMToolbar that defines PrintHello - so this should work:

tb.BMToolBar(self).PrintHello()

It worked with your commented lines because you did

from BMTest2 import BMToolbar

which results in BMToolbar beeing part of the global namespace, so you could
do

BMToolBar(self).PrintHello()

I suggest you re-read the tutorial sections covering modules for the
nitty-gritty details of importing.

-- 
Regards,

Diez B. Roggisch



More information about the Python-list mailing list