python constructing functions on the fly
<p>I have several little functions <code>f1</code>, <code>f2</code>, <code>f3</code> and a function <code>f</code>.</p>

<p>I want <code>f</code> to be a "container" to <code>f1</code>, <code>f2</code>, <code>f3</code>: to do the some of operations <code>f1</code>, <code>f2</code>, <code>f3</code>, depending on the program configuration (for example <code>f1</code> and <code>f2</code> or <code>f1</code> and <code>f3</code> or all the three) and nothing more.</p>

<p>I see two simple solutions: first to add some <code>if</code>'s in the function <code>f</code>:</p>

<pre><code>if configuration_f1_f2:
    f1()
    f2()
</code></pre>

<p>second, I can add a list of operations in <code>f</code>:</p>

<pre><code>for op in operations:
    op()
</code></pre>

<p>and add <code>f1</code>, <code>f2</code>, <code>f3</code> in <code>operations</code> or remove them, depending on configuration.</p>

<p>But can I somehow construct dynamically code of 'f' adding to it calls of <code>f1</code>, <code>f2</code> and <code>f3</code> exact what I need without any <code>if</code>'s or <code>list</code>'s or <code>for</code>'s? I mean something like on the fly code manipulation. So if my configuration is "<code>f1</code> and <code>f3</code>",  I set code of <code>f</code> so that it is </p>

<pre><code>f1()
f3()
</code></pre>

<p>and when my configuration changes to "<code>f2</code> and <code>f3</code>" I modify code of <code>f</code> to </p>

<pre><code>f2()
f3()
</code></pre>

<p>Can I manipulate the code of the function that way?</p>
