Function calling another function

Discussion in 'Python' started by Satish Chimakurthi, Mar 1, 2004.

  1. Hi all,

    My question is surely a basic one, but somehow, I am not able to figure it out.

    I have a python file "satish.py" as follows:


    *satish.py*
    def main():
    y()
    x()


    def y():
    ..
    ..

    def x():
    ...
    ..
    y()

    main()


    When I execute satish.py, main() executes. I was expecting y() to execute first and then x() and then y() again. I wanted function x() to be capable of calling function y(). With this form of code, seems like function x() is not recognising function y(). Is there any sort of import or anything else that I can do here ??



    Thanks in advance for your help

    Regards,
    Satish


    SATISH KUMAR CHIMAKURTHI
    Graduate Research Assistant
    CFD GROUP
    Mechanical Engineering
    UNIVERSITY OF KENTUCKY
    Lexington
    KENTUCKY - 40508
    U.S.A

    Email:
    Mobile:859-420-9890
    Office: 859-257-6336 X 80691
    Satish Chimakurthi, Mar 1, 2004
    #1
    1. Advertising

  2. > My question is surely a basic one, but somehow, I am not able to figure it
    > out.

    <snip>
    > When I execute satish.py, main() executes. I was expecting y() to execute
    > first and then x() and then y() again. I wanted function x() to be capable
    > of calling function y(). With this form of code, seems like function x()
    > is not recognising function y(). Is there any sort of import or anything
    > else that I can do here ??


    Works for me:

    def main():
    y()
    x()


    def y():
    print "y"

    def x():
    print "x"
    y()

    main()

    gives me:


    x
    y
    x

    As expected.
    --
    Regards,

    Diez B. Roggisch
    Diez B. Roggisch, Mar 1, 2004
    #2
    1. Advertising

  3. Hi all,

    Thanks a lot and sorry. It was an indentation mistake. Caused havoc for 30
    mins for me.


    Thanks again

    Regards,
    Satish


    ----- Original Message -----
    From: "Diez B. Roggisch" <>
    Newsgroups: comp.lang.python
    To: <>
    Sent: Monday, March 01, 2004 4:14 PM
    Subject: Re: Function calling another function


    > > My question is surely a basic one, but somehow, I am not able to figure

    it
    > > out.

    > <snip>
    > > When I execute satish.py, main() executes. I was expecting y() to

    execute
    > > first and then x() and then y() again. I wanted function x() to be

    capable
    > > of calling function y(). With this form of code, seems like function x()
    > > is not recognising function y(). Is there any sort of import or anything
    > > else that I can do here ??

    >
    > Works for me:
    >
    > def main():
    > y()
    > x()
    >
    >
    > def y():
    > print "y"
    >
    > def x():
    > print "x"
    > y()
    >
    > main()
    >
    > gives me:
    >
    >
    > x
    > y
    > x
    >
    > As expected.
    > --
    > Regards,
    >
    > Diez B. Roggisch
    > --
    > http://mail.python.org/mailman/listinfo/python-list
    Satish Chimakurthi, Mar 1, 2004
    #3
    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. John J
    Replies:
    2
    Views:
    391
  2. Andreas Lagemann
    Replies:
    8
    Views:
    464
    Mike Wahler
    Jan 10, 2005
  3. tiwy
    Replies:
    0
    Views:
    428
  4. Jon Clements
    Replies:
    3
    Views:
    303
    geremy condra
    Aug 6, 2010
  5. dutzend
    Replies:
    1
    Views:
    81
Loading...

Share This Page