importing / loading a module / class dynamically

Laszlo Nagy gandalf at designaproduct.biz
Fri Jan 5 12:04:23 EST 2007


> Thanks,
>
> What I am doing is adding plugin support to PyCrust ... so I'm looking for a
> mechanism where anyone can develop a plugin and have it loaded by pycrust.
>
> the .py was a typo 
>
>
> why the "...Have at least an empty plugin/name1/__init__.py file..." ?
>   
When you do

import plugins.name1.name1

then "plugins" and "plugins/name1" should be a package, not a module. A 
package is a special directory that contains package initialization code 
in a __init__.py file. If you do not have the file, then the "plugins" 
directory will be only a directory, and it cannot be imported.

For details, see:

http://docs.python.org/tut/node8.html#SECTION008400000000000000000

  Laszlo




More information about the Python-list mailing list