[Tutor] Function output
David Porter
jcm@bigskytel.com
Tue, 27 Jun 2000 07:11:22 -0600
* William Perry <wmperry@903internet.com>:
> >>> class rollum:
> def funct1 (self):
> s = " Hello World"
> return s
> def output (self):
> a = funct1()
> return a
'a = funct1()' should be 'a = self.funct1()'.
> >>> rollum.output()
> Traceback (innermost last):
> File "<pyshell#42>", line 1, in ?
> rollum.output()
> TypeError: unbound method must be called with class instance 1st argument
This error means that you need to create an instance of the class:
class Rollum:
def output(self):
s = " Hello World"
return s
r = Rollum()
print r.output()
I rewrote your code because the original output() function didn't do
anything more than funct1(). Also, this may be just a personal preference,
but I find python code much more easy to read if functions are written
without a space between the name and parenthesis (you do this half of the
time).
Hope this helps,
david.