Python Class instantiation: What does it mean when a class is called without accompanying arguments?
<p>I am trying to understand some code that I have found on github. Essentially there is a class called "HistoricCSVDataHandler" that has been imported from another module. In the main method this class is passed as a parameter to another class "backtest". </p>

<p>How can a class name that does not represent a instantiated variable be called without raising a NameError. </p>

<p>Or simply put :</p>

<p>Why/How is the class being called as:</p>

<pre><code>Backtest(HistoricCSVDataHandler)
</code></pre>

<p>Rather than:</p>

<pre><code>CSV_Handler = HistoricCSVDataHandler(foo,bar,etc)
Backtest(CSV_Handler)
</code></pre>

<p><a href="https://github.com/djunh1/event-driven-backtesting/blob/master/snp_forecast.py" rel="nofollow">See line 110 for code.</a></p>

<p>Regards</p>

<p>Think of python variables as labels, you can label a class (no instance), its like giving an alias to that class.</p>

<pre><code>&gt;&gt;&gt; class A(): pass
&gt;&gt;&gt; A
&lt;class __builtin__.A at 0x000001BE82279D08&gt;
&gt;&gt;&gt; b = A
&gt;&gt;&gt; b
&lt;class __builtin__.A at 0x000001BE82279D08&gt;
&gt;&gt;&gt; a = b()
&gt;&gt;&gt; a
&lt;__builtin__.A instance at 0x000001BE82269F48&gt;
&gt;&gt;&gt; A()
&lt;__builtin__.A instance at 0x000001BE82269708&gt;
</code></pre>

<p>Its the same with funtions parameters, you can pass a class (no instance) to the function for posterior use of it.</p>

<pre><code>&gt;&gt;&gt; def instantiator(c):
...     return c()
...     
&gt;&gt;&gt; c = instantiator(b)
&gt;&gt;&gt; c
&lt;__builtin__.A instance at 0x000001BE8226A148&gt;
&gt;&gt;&gt; c = instantiator(A)
&gt;&gt;&gt; c
&lt;__builtin__.A instance at 0x000001BE8226A288&gt;
</code></pre>

python class