Conditional based on whether or not a module is being used

Martin P. Hellwig martin.hellwig at dcuktec.org
Fri Mar 5 15:06:09 EST 2010


On 03/05/10 19:24, Pete Emerson wrote:
> In a module, how do I create a conditional that will do something
> based on whether or not another module has been loaded?
<cut>>
> If someone is using foo module, I want to take advantage of its
> features and use it in foobar, otherwise, I want to do something else.
> In other words, I don't want to create a dependency of foobar on foo.
>
> My failed search for solving this makes me wonder if I'm approaching
> this all wrong.
>
> Thanks in advance,
> Pete

Hmm how about the module is available, just not imported yet, I would 
assume that you still would like to use the module then.
Perhaps playing around with the imp module might get you what you mean 
instead of what you say?

-- 
mph




More information about the Python-list mailing list