Conditional based on whether or not a module is being used

Terry Reedy tjreedy at
Fri Mar 5 23:16:00 CET 2010

On 3/5/2010 4:29 PM, Pete Emerson wrote:
> On Mar 5, 1:14 pm, Chris Rebert<c... at>  wrote:

> I want to write other modules, and my thinking is that it makes sense
> for those modules to use the "logger" module to do the logging, if and
> only if the parent using the other modules is also using the logger
> module.
> In other words, I don't want to force someone to use the "logger"
> module just so they can use my other modules, even if the "logger"
> module is installed ... but I also want to take advantage of it if I'm
> using it.
> Now that I've written that, I'm not sure that makes a whole lot of
> sense. It seems like I could say, "hey, this person has the 'logger'
> module available, let's use it!".

Except in unusual cases, where merely importing a modules uses 
substantial resources, I would say that if it is available, use it.

More information about the Python-list mailing list