Getting unbound method error?
<p>I tried to run this code below  </p>

<pre><code>class TestStaticMethod:  
    def foo():  
        print 'calling static method foo()'  

        foo = staticmethod(foo) 

class TestClassMethod:  
    def foo(cls):  
        print 'calling class method foo()'  
        print 'foo() is part of class: ', cls.__name__  

    foo = classmethod(foo)  
</code></pre>

<p>After I ran this with the code below </p>

<pre><code>tsm = TestStaticMethod()
TestStaticMethod.foo() 
</code></pre>



<pre><code>Traceback (most recent call last):  
  File "&lt;pyshell#35&gt;", line 1, in &lt;module&gt;  
    TestStaticMethod.foo()  
TypeError: unbound method foo() must be called with TestStaticMethod instance as first argument (got nothing instead)  
</code></pre>



<pre><code>tsm.foo()
</code></pre>



<pre><code>Traceback (most recent call last):  
  File "&lt;pyshell#36&gt;", line 1, in &lt;module&gt;  
    ts.foo()  
TypeError: foo() takes no arguments (1 given)
</code></pre>

<p>I really don't get why I'm getting the unbound method. Can anyone help me?  </p>

<p>You should not indent </p>

<blockquote>
  <p>foo = staticmethod(function_name)</p>
</blockquote>

<p>in function(foo) itself,</p>

<p>Instead give this a try:</p>

<pre><code>class TestStaticMethod:  
    def foo():  
        print 'calling static method foo()'  
    foo = staticmethod(foo)
</code></pre>

<p>or </p>

<pre><code>class TestStaticMethod:  
    @staticmethod
    def foo():  
        print 'calling static method foo()'
</code></pre>

<p>Both above solutions will work</p>

python