Confusion with calling function of a subclass

Adonis Vargas adonis at REMOVETHISearthlink.net
Fri Dec 22 02:49:26 EST 2006


Pyenos wrote:
> class TREE:
>     def gettree(self):print self
> TREE.gettree() # I get an error saying 
>                # TypeError: unbound method gettree() must be called
>                # with TREE instance as first argument (got nothing instead
> 
> 
> I still don't understand how to solve this simple code. 

You first need to create an instance of the class:

tree = TREE()
tree.gettree()

or

TREE().gettree()

Hope this helps.

Adonis

P.S. You should look into the tutorial 
http://docs.python.org/tut/tut.html it will answer a lot of your questions.



More information about the Python-list mailing list