keyword that stops further processing of a Python script

A

Avi Kak

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
 
D

Dave Benjamin

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

Peter Otten

Avi said:
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
 
M

Miki Tebeka

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
 
A

Avi Kak

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
 

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,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top