473,385 Members | 1,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Confusion with calling function of a subclass

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.
Dec 22 '06 #1
3 1165
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.
Dec 22 '06 #2
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.
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>

Dec 22 '06 #3
Adonis Vargas <ad****@REMOVETHISearthlink.netwrites:
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.
Yes, it definitely solved my problem. Thank you very much. :D
Dec 22 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Mathias Mamsch | last post by:
Hi, I have some confusion concerning the weakref module. I am trying to save a weak reference to a bound member function of a class instance for using it as a callback function. But I always...
38
by: Grant Edwards | last post by:
In an interview at http://acmqueue.com/modules.php?name=Content&pa=showpage&pid=273 Alan Kay said something I really liked, and I think it applies equally well to Python as well as the languages...
4
by: erick_bodine | last post by:
In Martinelli's Nutshell book in the Exceptions chapter there is an example of a custom exception class (pg.112) that I am trying to implement without success. The custom exception class example...
3
by: john | last post by:
I have a situation where i have a base class and a sub-class. A null instance of the sub-class is passed into a function. The function needs to create a new instance of the sub-class, but the...
4
by: Claire | last post by:
I'm having real brain failure today. I've done this lots of times with constructors but not with virtual methods and the compiler complains because Ive put the :base(foo) after the function...
23
by: Jeff | last post by:
After reading all I could find about auto_ptr, I decided to write a little program to test my comprehension: #include <iostream> #include <memory> class A { public: void say_hi() {...
12
by: Ramon | last post by:
Hello I'm new to OOP in PHP and I have this question: I have a class called "Form", which contains a collection of classes (objects) called "Textbox". Now I need to call the Textbox class's...
5
sumittyagi
by: sumittyagi | last post by:
Hi all, I was reading factory method pattern from wikipedia link. There are some limitations mentioned three limitations mentioned there. These are all fine. But there is a conclusion...
3
by: bassman2112 | last post by:
I'm having issues with calling a method defined in a subclass on a superclass object. This program is an exercise using inheritance, with an Employee superclass, Salaried and Hourly classes that...
1
by: MorgyTheMole | last post by:
I have a base class: class A { protected: static void* operator new (size_t size); void operator delete (void *p); public: void Delete(); }
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.