class-call a function in a function -problem

Elmo Mäntynen elmo13 at jippii.fi
Tue Aug 16 15:31:35 EDT 2005


On Tue, 16 Aug 2005 18:45:51 +0200, wierus wrote:

>  Hello, i have a problem. I write my first class in python so i'm not a 
> experience user.  I want to call a function in another function, i tried to 
> do it in many ways, but i always failed:(
> I supposed it's sth very simple but i can't figure what it is:
> ==================================
> class ludzik:
>  x=1
>  y=2
>  l=0 
#is this L or I^?
>  def l(self): 
#What about this^. You are strongly advised to use more obvious and more
easily distinguishable names.
>   ludzik.l=ludzik.x+ludzik.y
>   print ludzik.l
This is a normal instance method ^

> 
>  def ala(self):
>   print ludzik.x
>   print ludzik.y
>   ludzik.l()
If call normal method through a class you get an unbound method, so you
have to provide explicitly an instance of that class: ludzik.l(self). If
you don't want to do that, go read about class methods in the official
tutorial.

> 
> 
> z=ludzik()
> z.ala()
> ====================================
> 
> 
> k.py
> 1
> 2
> Traceback (most recent call last):
>   File "k.py", line 17, in ?
>     z.ala()
>   File "k.py", line 14, in ala
>     ludzik.l()
> TypeError: unbound method l() must be called with ludzik instance as
> first argument (got nothing instead)
> 
> 
> i would be gratefull for resolving this problem for me....

Elmo



More information about the Python-list mailing list