[Tutor] functions and errors

alan.gauld@bt.com alan.gauld@bt.com
Wed, 22 May 2002 18:21:21 +0100


> class accountcurrents:
>     def __init__(self):
>         print "Hello"
> 
>     def finnxlpolicy():
      def finnxlpolicy(self):  #<--- Need to have a self argument

>         print "world"
> 
> how can I get this to print world? 

> If I write n = accountcurrents(), n.finnxlpolicy() 

This combination should now work as expected.

> TypeError: finnxlpolicy() takes no arguments (1 given)
> What do I do wrong? Thanks in advance....

The error is because when you call n.finnxlpolicy()
The interpreter sees it as:

finnxlpolicy(n)

With 'n' used as the "self" in your function definition.
Thus you are passing an argument but hads not defined 
the function to accept any parameters. Python didn't 
like that.

HTH,

Alan g.
Author of the 'Learning to Program' web site
http://www.freenetpages.co.uk/hp/alan.gauld