class-call a function in a function -problem

Discussion in 'Python' started by wierus, Aug 16, 2005.

  1. wierus

    wierus Guest

    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....
     
    wierus, Aug 16, 2005
    #1
    1. Advertising

  2. 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
     
    =?iso-8859-1?q?Elmo_M=E4ntynen?=, Aug 16, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. E11
    Replies:
    1
    Views:
    4,791
    Thomas Weidenfeller
    Oct 12, 2005
  2. wierus
    Replies:
    4
    Views:
    407
    Bengt Richter
    Aug 16, 2005
  3. grbgooglefan
    Replies:
    2
    Views:
    433
    Pascal Bourguignon
    Jan 30, 2008
  4. George2
    Replies:
    0
    Views:
    355
    George2
    Mar 17, 2008
  5. THAKUR PRASHANT SINGH

    Class Function call vs Normal Function call

    THAKUR PRASHANT SINGH, Feb 26, 2010, in forum: Ruby
    Replies:
    7
    Views:
    195
    THAKUR PRASHANT SINGH
    Feb 27, 2010
Loading...

Share This Page