On Class namespaces, calling methods
mehgcap at gmail.com
Sat Apr 10 16:52:56 CEST 2010
On 4/10/10, vsoler <vicente.soler at gmail.com> wrote:
> 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:
> def m():
> print "mouse"
print "mouse" #I believe
> Say that I have this "silly" class.
> While I can then write
> print Uno.a
> I cannot write
> 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.
I believe that self is always passed, whether you have an instance of
the uno class or not. Since you did not tell m() to expect self to be
passed to it, and self is passed anyway, m() has this self and has no
idea what to do with it. Also, you must make an uno object (u=uno())
then call methods off that object (u.m()) since not doing so means the
uno class will not get initialized.
> Could anybody explain what argument is being supplied to the method?
> Is ther any workaround to call the m function?
> Thank you
Have a great day,
Alex (msg sent from GMail website)
mehgcap at gmail.com; http://www.facebook.com/mehgcap
More information about the Python-list