Python

NAVIGATION
CATEGORIES
REFERRENCE
LINKS
  • Controlling Where My Program Ends

    2 answers - 1331 bytes - related search similar search Add To My Delicious Add To My Stumble Upon Add To My Google Mark Add To My Facebook Add To My Digg Add To My Reddit

    Subject:
    Re: [Tutor] Controlling Where My Program Ends
    From:
    Don Parris <webdev (AT) matheteuo (DOT) org>
    Date:
    Tue, 14 Jun 2005 23:03:59 -0400
    To:
    tutor (AT) python (DOT) org
    To:
    tutor (AT) python (DOT) org
    Wed, 15 Jun 2005 00:59:24 -0000
    "DC Parris" <webdev (AT) matheteuo (DOT) orgwrote:

    >>Never mind. I found it - sys.exit()
    >>
    >>Sorry to have wasted the bandwidth/time.

    This was in reference to a post about exiting from a program. I couldn't
    figure out why my program wouldn't let me exit from within a sub-menu of the
    console interface. Since my webmail client goofed up the "from" header, it
    never showed up, and I've cancelled it to avoid wasting everyone's time
    further. I found sys.exit() in the library reference, which allows me to do
    what I want.
    Don
    If you use the if __name__ == '__main__': idiom, then you can just use return
    instead of sys.exit()
    def main():
    lotsa interesting python code
    if somethinorother:
    # sys.exit()
    return
    more interesting python code
    if __name__ == '__main__':
    main()
    Tutor maillist - Tutor (AT) python (DOT) org
  • No.1 | | 2240 bytes | |

    Wed, 15 Jun 2005 07:46:40 -0600
    Mike Hansen <mhansen (AT) cso (DOT) atmel.comwrote:

    Subject:
    Re: [Tutor] Controlling Where My Program Ends
    From:
    Don Parris <webdev (AT) matheteuo (DOT) org>
    Date:
    Tue, 14 Jun 2005 23:03:59 -0400
    To:
    tutor (AT) python (DOT) org

    To:
    tutor (AT) python (DOT) org

    Wed, 15 Jun 2005 00:59:24 -0000
    "DC Parris" <webdev (AT) matheteuo (DOT) orgwrote:


    >>Never mind. I found it - sys.exit()
    >>
    >>Sorry to have wasted the bandwidth/time.


    This was in reference to a post about exiting from a program. I
    couldn't figure out why my program wouldn't let me exit from within a
    sub-menu of the console interface. Since my webmail client goofed up
    the "from" header, it never showed up, and I've cancelled it to avoid
    wasting everyone's time further. I found sys.exit() in the library
    reference, which allows me to do what I want.

    Don

    If you use the if __name__ == '__main__': idiom, then you can just use
    return instead of sys.exit()

    def main():
    lotsa interesting python code
    if somethinorother:
    # sys.exit()
    return
    more interesting python code

    if __name__ == '__main__':
    main()

    Thanks. I'll try that out a little later (when I get back to this).
    Incidentally, my menu system started off quite klunky, but I've thrown my
    menu items into dictionaries and iterate through them to display the menu.
    Thus, instead of:
    print 'menuitem'
    print 'menuitem'
    etc., etc., etc.

    I now have:
    for i in menu.iteritems():
    print repr(key), '', 'value'

    Now if I can figure out how to iterate through the if elif statements,
    I'll be able to shorten the code a bit further. First things first though.
    Let me just understand these basic things, and then I'll see if I can get a
    little smarter.

    Maybe I'll start a thread "trials of a Python newbie". It'll be hilarious
    for the old timers, I'm sure. It might help other newbies as well.

    Don
  • No.2 | | 1174 bytes | |

    >>Never mind. I found it - sys.exit()

    You can do the same thing by

    raise SystemExit

    This avoids the need to import sys

    Alan G.


    >>
    >>Sorry to have wasted the bandwidth/time.


    --
    This was in reference to a post about exiting from a program. I
    couldn't
    figure out why my program wouldn't let me exit from within a
    sub-menu of the
    console interface. Since my webmail client goofed up the "from"
    header, it
    never showed up, and I've cancelled it to avoid wasting everyone's
    time
    further. I found sys.exit() in the library reference, which allows
    me to do
    what I want.

    Don
    --
    If you use the if __name__ == '__main__': idiom, then you can just
    use return
    instead of sys.exit()

    def main():
    lotsa interesting python code
    if somethinorother:
    # sys.exit()
    return
    more interesting python code

    if __name__ == '__main__':
    main()
    >
    >
    >


    Tutor maillist - Tutor (AT) python (DOT) org

Re: Controlling Where My Program Ends


max 4000 letters.
Your nickname that display:
In order to stop the spam: 6 + 5 =
QUESTION ON "Python"

EMSDN.COM