passing no arguments to a callback function question

Peter Hansen peter at engcorp.com
Tue Apr 8 05:22:28 EDT 2003


matthew wrote:
> 
> I'm pretty new to python and most of my stumblings get me somewhere but
> I'm stumped on this. Given the following code/exception how do I avoid
> the exception generated when notify_listeners is called?
> 
>      def print_params():
>         print 'PARAMS: ', params
> 
> gives:-
> 
>    File "D:\Python22\Lib\site-packages\TeePee\notifier.py", line 39, in
> __call__
>      return self.fn(*(self.args + args), **d)
> TypeError: print_params() takes no arguments (1 given)

You *always* need to include the self argument in methods.

Change that to "def print_params(self):" and it will work...  actually,
you may need to use "self.params" in the code too.  Python is *explicit*
about instance attributes, unlike some other languages.

-Peter




More information about the Python-list mailing list