On Class namespaces, calling methods

vsoler vicente.soler at gmail.com
Sat Apr 10 16:26:35 CEST 2010


Still learning python, especially OOP.

While testing classes, I sometimes think of them as "ordinary
containers" of values and functions (methods). That is, values and
functions can be grouped together inside "namespaces" calles classes.

class Uno:
    a=1
    def m():
        print "mouse"

Say that I have this "silly" class.

While I can then write

      print Uno.a

I cannot write
      Uno.m()

I get the following error message:

     TypeError: m() takes no arguments (1 given)

Since I have not created any instances of Uno, there is no self
object, and I do not understand what object is supplied to the
function call.

Could anybody explain what argument is being supplied to the method?
Is ther any workaround to call the m function?

Thank you



More information about the Python-list mailing list