I'm using ArcGIS 10 and I'm practicing a few scripts with Python. What command should I use, if I want to exit a commnad, or a function? I'm always stuck with 3 dots (secondary prompt). How do I stop it?
I've tried:
sys.exit()
sys.exit(0)
quit()
I'm using ArcGIS 10 and I'm practicing a few scripts with Python. What command should I use, if I want to exit a commnad, or a function? I'm always stuck with 3 dots (secondary prompt). How do I stop it?
I've tried:
sys.exit()
sys.exit(0)
quit()

I usually use sys.exit() to stop a script from running if some error condition is met. So for example, if a user put in a wrong input variable...
You might be intersted in the pass or break statements too...Code:import sys var =gp.GetParameterAsText(0) if var not in ("cat","dog","mouse"): print "ERROR: You entered the wrong animal! Exiting script..."; sys.exit() else: print var + " is a valid entry. Good job!"
pass is used to basically 'do nothing', so something like:
break is used to break out of a while or for loop, so something like:Code:if animal == "dog": pass #aka don't do anything else: print "not a dog"
Code:for x in (1,2,3,4,5): if x > 4: break #aka stop looping else: print x
Thanks for the reply and the useful info. However, it's not really what I need. I'm trying to stop everthing and go back to the >>>. But I can't, I'm always stuck with the three dots (...).
For example, if I type the following command (import sys) and I decide to change my mind and exit out of that command, how would I do it? The sys.exit() doesn't work.
Here's what I get:
>>> import sys
... sys.exit()
...
I'm always stuck with the 3 dots...why?

Not sure what you mean exactly...
And you are hitting the enter button after typing 'import sys', right?
Are you entering these commands at the prompt in:
-python.exe (the DOS-looking window)
-pythonwin.exe (the freebee python IDE)
-the python window in ArcMap
-something else?
I'm doing it in Python in ArcMap and yes, I do hit Enter at the end of the line. I have experience with VBA and C++, but not with Python. The compiler is really different; it's like scripting live, instead of hitting a RUN button, when you are done scripting....it's more similar to DOS, then anything else. It takes some getting used to!
I'm just looking for the magic command, to get out of any command that I'm in.
Last edited by davecouture; 03-31-2011 at 11:15 AM.
The magic command you're probably looking for is Ctrl-C (Ctrl-Break on some machines), but disappointingly, it does not work at the ArcGIS Python prompt, and even in a standalone console window, if the arcgisscripting (and presumably arcpy) module is loaded then the expected Ctrl-C behavior (throwing a KeyboardInterrupt exception) is broken. I detailed this problem and a workaround here, but again this would most likely not work within the ArcGIS Python prompt presumably because the keyboard accelerators used by the main application are probably lower level/higher priority so they don't reach the Python interpreter.
What specific commands are locking you up? An import statement as in your example should not cause multi-line entry nor long execution times. If statements, loops, try/except/finally constructs and function definitions can though, and the termination/exit command for those are various, such as pass, break, or return. When entering a multi-line construct if you just hit enter or escape does it not return you to the main command prompt?
For anything more significant than poking around arcpy or calling single GP tools you should probably be writing scripts in a real IDE instead of using the ArcGIS Python prompt anyways.
Thanks for all the info, I'll try the IDE.

The ArcMap Python window "claims" that Esc will do it, but... not so sure.
Bookmarks