Several modules in a package importing one common module

Posted by morpheous on Stack Overflow See other posts from Stack Overflow or by morpheous
Published on 2010-06-01T14:21:55Z Indexed on 2010/06/01 14:23 UTC
Read the original article Hit count: 157

Filed under:
|

I am writing a python package. I am using the concept of plugins - where each plugin is a specialization of a Worker class. Each plugin is written as a module (script?) and spawned in a separate process.

Because of the base commonality between the plugins (e.g. all extend a base class 'Worker'), The plugin module generally looks like this:

import commonfuncs

def do_work(data): # do customised work for the plugin print 'child1 does work with %s' % data

In C/C++, we have include guards, which prevent a header from being included more than once.

Do I need something like that in Python, and if yes, how may I make sure that commonfuncs is not 'included' more than once?

© Stack Overflow or respective owner

Related posts about python

Related posts about beginner