How to create a list of functions for call in python
<p>My question is like this one here, but I don't understand.</p>

<p><a href="http://stackoverflow.com/questions/26881396/how-to-add-a-function-call-to-a-list#">How to add a function call to a list?</a></p>

<p>If I had approximately 10 commands, and they all served specific purposes, so they couldn't be modified, but I wanted to put them in a list without calling them.</p>

<pre><code>def print_hello():
    print("hello")
command_list=[print_hello()]
</code></pre>

<p>This would only print <code>"hello"</code>, then leave <code>command_list</code> equal to <code>[None]</code></p>

<p>How would I get it so that when I type <code>command_list[0]</code>, it would perform <code>print_hello()</code>?</p>

<p>If you want to add it to the list without calling them, just refrain from calling them:</p>

<pre><code>command_list=[print_hello]
</code></pre>

<p>At the time you want to call them, call them:</p>

<pre><code>command_list[0]()
</code></pre>

<p>If you want something to happen by just doing <code>command_list[0]</code>, you could subclass <code>list</code> and give it a</p>

<pre><code>def __getitem__(self, index):
    item = list.__getitem__(self, index)
    return item()
</code></pre>

<p>(untested). Then the item getting operation on the lists causes the function to be called.</p>

python list