Confusion with calling function of a subclass

P

Pyenos

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.
 
A

Adonis Vargas

Pyenos said:
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.
 
F

Fredrik Lundh

Pyenos said:
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.

what is it supposed to do? what do you expect "self" to be, and where
do you expect it to come from ? have you tried adding some expletives,
to see if that solves the problem ?

</F>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top