"Breaking" the __main__ script

V

vsoler

Hello,

I am still learning python, thus developnig small scripts.

Some of them consist only of the main module. While testing them
(debugging) I sometimes want to stop the script at a certain point,
with something like stop, break, end or something similar.

What statement can I use?

Vicente Soler
 
M

Mark Lawrence

vsoler said:
Hello,

I am still learning python, thus developnig small scripts.

Some of them consist only of the main module. While testing them
(debugging) I sometimes want to stop the script at a certain point,
with something like stop, break, end or something similar.

What statement can I use?

Vicente Soler

Something like
import sys
sys.exit()?

HTH.

Mark Lawrence
 
M

Michael Rudolf

Am 14.03.2010 12:53, schrieb Mark Lawrence:
Something like
import sys
sys.exit()?

Or just "raise SystemExit", "raise SyntaxError" or any other Exception.
But you won't have to: If you use IDLE, you can just set breakpoints in
your code: enable the debugger in debug-debugger and set breakpoints via
right click in your source file.

Or you could use a real debugger, like pdb
http://docs.python.org/library/pdb.html

HTH,
Michael
 
S

Steve Holden

Mark said:
Something like
import sys
sys.exit()?

HTH.

I think it's less than likely that it will help, since once sys.exit()
is called the program is no longer available for inspection.

The OP is probably looking for the "pdb" module in the standard library.
The documentation is good enough to get you started.

regards
Steve
 
J

Joaquin Abian

Hello,

I am still learning python, thus developnig small scripts.

Some of them consist only of the main module. While testing them
(debugging) I sometimes want to stop the script at a certain point,
with something like    stop, break, end   or something similar.

What statement can I use?

Vicente Soler

Hola Vicente,

You need a debugger.
A practical solution to start with is to use an IDE with an integrated
debugger.
Stani's Python Editor (SPE) is a lightweight IDE with pdb integrated
(with style checker also).
It is a very good ide for learning (simple and not cluttered) but also
for medium size
applications (it is very well designed).

atb

Joaquin
 
T

Tim Chase

Any reason you prefer PDB over WinPDB?
http://winpdb.org/

I always count "in the standard library" as a big plus over any
add-ons It's nice to know about alternatives such as WinPDB, but
everybody that has python also has pdb already installed.

-tkc
 
J

Joaquin Abian

Am 14.03.2010 16:03, schrieb (e-mail address removed):


Yes. I don't have Windows except one one PC :p

Sorry, i hit the wrong key. Again:
winpdb is crossplatform. It uses a wxwindows gui.
Names are not really fortunate...
I have installed the last winpdb 1.4.6 in SPE today.

atb
joaquin
 
M

Michael Rudolf

Am 14.03.2010 21:08, schrieb (e-mail address removed):
WinPDB runs on non-Windows platforms :)
Uh, OK.
Then the name mislead me ;)

But yeah, I prefer a console based debugger.
 
J

Jean-Michel Pichavant

Steve said:
One might reasonably argue that it has a pretty couter-intuitive name, then.

regards
Steve
'Win' may stand for Winner, not Windows :D

JM
 
J

Jean-Michel Pichavant

vsoler said:
Hello,

I am still learning python, thus developnig small scripts.

Some of them consist only of the main module. While testing them
(debugging) I sometimes want to stop the script at a certain point,
with something like stop, break, end or something similar.

What statement can I use?

Vicente Soler
import bdb

pdb.set_trace() # put this line anywhere you want a breakpoint in your code.

type n for next, c for continue, s for step into and google for 'python
pdb' for the details.

JM
 
J

Jean-Michel Pichavant

Jean-Michel Pichavant said:
import bdb

pdb.set_trace() # put this line anywhere you want a breakpoint in your
code.

type n for next, c for continue, s for step into and google for
'python pdb' for the details.

JM
erratum

import pdb
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top