execute code depending on the available libraries
<p>suppose I have a function:</p>

<pre><code> def mean(data):
     return sum(data)/len(data)
</code></pre>

<p>now, if on the system you have numpy it is better to define it as:</p>

<pre><code>def man(data):
     return np.mean(data)
</code></pre>

<p>if you have advanced libraries as <a href="http://code.google.com/p/numexpr/" rel="nofollow">numexpr</a> it is better to do:</p>

<pre><code>def mean(data):
     return ne.evaluate("sum(data)") / len(data)
</code></pre>

<p>now... I want to use one of the previous depending on the fact that one library is available or not. What is the better way to do in in python? For example in c/c++ I would have used macros like</p>

<pre><code>#ifdef HAS_NUMPY
...
#elseif HAS_NUMEXPRE
...
</code></pre>
