473,396 Members | 1,599 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Stopping Execution

Hey everyone. I remember from my C programming that I can either use
the exit() or return() functions to end execution of the main code
block. My question is, is there a way for me to do this in Python? I
know there has to be, but I can't for the life of me figure out what it
is. The reason I ask is that I need to conditionally end a script I'm
writing at various places. Thanks in advance.

James

--
My blog: http://www.crazydrclaw.com/
My homepage: http://james.colannino.org/

"A well regulated militia being necessary to the security of a free
state, THE RIGHT of the people to keep and bear arms SHALL NOT BE
INFRINGED." --United States Constitution, Second Ammendment

Nov 10 '05 #1
4 1225
import sys
sys.exit

Nov 10 '05 #2
ro***********@gmail.com wrote:
import sys
sys.exit


$ more test.py
import sys
print "should get here"
sys.exit
print "should never get here"

$ python test.py
should get here
should never get here

</F>

Nov 10 '05 #3
Fredrik Lundh wrote:
ro***********@gmail.com wrote:

import sys
sys.exit

$ more test.py
import sys
print "should get here"
sys.exit
print "should never get here"

$ python test.py
should get here
should never get here

Which is Fredrik's way of telling you you need to *call* sys.exit and
not just reference it (works in Perl, which assumes you want to call it,
but in Python "explicit is better than implicit").

$ more test.py
import sys
print "should get here"
sys.exit()
print "should never get here"

$ python test.py
should get here

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/

Nov 11 '05 #4
surely you mean

sys.exit()

Gerry
Nov 11 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Toni | last post by:
Hello I'm a newbie in VB .NET and I'd like to accomplish a (I think) very simple task. What I want to do is throw an error message to the user whenever something happens. The main point is...
5
by: Jack | last post by:
Hi, I have a asp page which is pretty long. This consitst of various recordsets. My intention is to stop execution of a code at a cetain point and test one value prior to this point. Is there any...
2
by: Ranjith | last post by:
We have a console.php which takes in SQL queries and displays them in a result.php webpage. Sometimes the query takes minutes to execute or crashes the PHP application. Is it possible to cancel...
12
by: VMI | last post by:
My Windows form has two buttons: "Start" and "Stop". How can I stop the form from doing whatever it is doing without closing the whole application? The "Stop" button would have to stop a process...
1
by: Matthew Brown | last post by:
Hi, I am working with a COM library in which modifying almost every object is done asynchronously (because the object represent physical devices across a network somewhere on a telephone...
1
by: Selva Chinnasamy | last post by:
I have read large amount of data from Ms-Access database to build BinaryArray. I like to know how can I stop the current execution after it is statrted. Functions build the Binary array is not...
4
by: bjm | last post by:
I am writing a program that will automate a series of application installations. I want to give the user the option of stopping the program's execution in between installations (for example, give...
0
by: eldamiani | last post by:
Ineed a help. I want to ask, how I can do dialog box window which is a normal form, but causes stopping the code execution in form which call out this dialog box. I have ...
0
by: PyNoob | last post by:
By default, uncaught exceptions stop the execution of python scripts (similar to what bash does when -e us set.) I need to change this behavior, so that the user gets informed about the uncaught...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.