keyword that stops further processing of a Python script

Discussion in 'Python' started by Avi Kak, Feb 17, 2004.

  1. Avi Kak

    Avi Kak Guest

    Hello:

    Does Python provide a token like Perl's __END__
    that would mark the logical end of a Python script
    which could occur before the actual end of the file.

    I have found Perl's __END__ token to be very useful
    for debugging scripts. So I was wondering if
    Python provided a similar facility.

    Avi Kak
     
    Avi Kak, Feb 17, 2004
    #1
    1. Advertising

  2. In article <>, Avi Kak wrote:
    >
    > Does Python provide a token like Perl's __END__
    > that would mark the logical end of a Python script
    > which could occur before the actual end of the file.
    >
    > I have found Perl's __END__ token to be very useful
    > for debugging scripts. So I was wondering if
    > Python provided a similar facility.


    I think it's denoted by an endless expanse of significant whitespace.
    Har, har. Sorry, couldn't resist.

    --
    ..:[ dave benjamin: ramen/[sp00] -:- spoomusic.com -:- ramenfest.com ]:.
    : d r i n k i n g l i f e o u t o f t h e c o n t a i n e r :
     
    Dave Benjamin, Feb 17, 2004
    #2
    1. Advertising

  3. Avi Kak

    Peter Otten Guest

    Avi Kak wrote:

    > Does Python provide a token like Perl's __END__
    > that would mark the logical end of a Python script
    > which could occur before the actual end of the file.
    >
    > I have found Perl's __END__ token to be very useful
    > for debugging scripts. So I was wondering if
    > Python provided a similar facility.


    I use sys.exit("debug") which exits from the logical rather than the text
    flow. As an alternative you could reserve one kind of docstrings to
    neutralize arbitrary chunks of code - e. g. I never use ''' ... '''. Last
    not least: every decent editor provides comment/uncomment commands.

    Peter
     
    Peter Otten, Feb 17, 2004
    #3
  4. Avi Kak

    Miki Tebeka Guest

    Hello Avi,

    > Does Python provide a token like Perl's __END__
    > that would mark the logical end of a Python script
    > which could occur before the actual end of the file.

    Just place `raise SystemExit' where you want the script to stop.
    Another option of to use triple quotes around the end of the file.

    HTH.
    Miki
     
    Miki Tebeka, Feb 17, 2004
    #4
  5. Avi Kak

    Avi Kak Guest

    Hello:

    I would like to thank Peter Otten and Miki Tebeka
    for posting their replies. I was getting tired of
    having to repeatedly comment out and uncomment my
    long scripts during their development.

    To summarize what Peter and Miki said, the logical
    end of a script can be marked either with sys.exit("debug")
    or with 'raise SystemExit'. Another option is to
    put triple quotes around the part of the script you
    don't want to see executed.

    In retrospect, all three suggestions --- especially the
    one about using triple quotes --- should have been
    obvious to me. But that's the way the human brain works.
    Sometimes what's seemingly the most obvious is not so
    obvious until someone else points out its obviousness.

    Avi

    On 17 Feb 2004 03:26:28 -0800, (Miki Tebeka)
    wrote:

    >Hello Avi,
    >
    >> Does Python provide a token like Perl's __END__
    >> that would mark the logical end of a Python script
    >> which could occur before the actual end of the file.

    >Just place `raise SystemExit' where you want the script to stop.
    >Another option of to use triple quotes around the end of the file.
    >
    >HTH.
    >Miki
     
    Avi Kak, Feb 17, 2004
    #5
    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. Jason
    Replies:
    2
    Views:
    2,550
    =?Utf-8?B?U3RldmUgSw==?=
    Jun 10, 2004
  2. Replies:
    6
    Views:
    468
    Peter Otten
    May 10, 2007
  3. Hamilton, William

    RE: keyword checker - keyword.kwlist

    Hamilton, William, May 10, 2007, in forum: Python
    Replies:
    4
    Views:
    363
  4. jaffarkazi
    Replies:
    0
    Views:
    266
    jaffarkazi
    Aug 1, 2008
  5. sOliver
    Replies:
    2
    Views:
    375
    sOliver
    Jan 20, 2009
Loading...

Share This Page