class-call a function in a function -problem

W

wierus

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
def l(self):
ludzik.l=ludzik.x+ludzik.y
print ludzik.l

def ala(self):
print ludzik.x
print ludzik.y
ludzik.l()


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....
 
?

=?iso-8859-1?q?Elmo_M=E4ntynen?=

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top