Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

"Breaking" the __main__ script

4 views
Skip to first unread message

vsoler

unread,
Mar 14, 2010, 7:34:53 AM3/14/10
to
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

Mark Lawrence

unread,
Mar 14, 2010, 7:53:22 AM3/14/10
to pytho...@python.org

Something like
import sys
sys.exit()?

HTH.

Mark Lawrence

Michael Rudolf

unread,
Mar 14, 2010, 8:20:03 AM3/14/10
to
Am 14.03.2010 12:53, schrieb Mark Lawrence:

> vsoler wrote:
>> 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?
> 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

Steve Holden

unread,
Mar 14, 2010, 9:07:21 AM3/14/10
to pytho...@python.org
Mark Lawrence wrote:
> 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
--
Steve Holden +1 571 484 6266 +1 800 494 3119
See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/
Holden Web LLC http://www.holdenweb.com/
UPCOMING EVENTS: http://holdenweb.eventbrite.com/

Joaquin Abian

unread,
Mar 14, 2010, 10:03:29 AM3/14/10
to

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

pyt...@bdurham.com

unread,
Mar 14, 2010, 11:03:47 AM3/14/10
to Michael Rudolf, pytho...@python.org
Michael,

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

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

Thanks,
Malcolm

Tim Chase

unread,
Mar 14, 2010, 2:30:59 PM3/14/10
to pyt...@bdurham.com, pytho...@python.org, Michael Rudolf
pyt...@bdurham.com wrote:
>> Or you could use a real debugger, like pdb
>> http://docs.python.org/library/pdb.html
>
> 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

Michael Rudolf

unread,
Mar 14, 2010, 3:35:14 PM3/14/10
to
Am 14.03.2010 16:03, schrieb pyt...@bdurham.com:
> Any reason you prefer PDB over WinPDB?
> http://winpdb.org/

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

pyt...@bdurham.com

unread,
Mar 14, 2010, 4:08:21 PM3/14/10
to Michael Rudolf, pytho...@python.org
>> Any reason you prefer PDB over WinPDB?
>> http://winpdb.org/

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

WinPDB runs on non-Windows platforms :)

Malcolm

Joaquin Abian

unread,
Mar 14, 2010, 4:11:29 PM3/14/10
to

WinPdb is crossplatform. Is build with

Joaquin Abian

unread,
Mar 14, 2010, 4:18:19 PM3/14/10
to
On 14 mar, 20:35, Michael Rudolf <spamfres...@ch3ka.de> wrote:

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

Michael Rudolf

unread,
Mar 14, 2010, 4:32:30 PM3/14/10
to
Uh, OK.
Then the name mislead me ;)

But yeah, I prefer a console based debugger.

Steve Holden

unread,
Mar 14, 2010, 4:55:20 PM3/14/10
to pytho...@python.org
pyt...@bdurham.com wrote:
>>> Any reason you prefer PDB over WinPDB?
>>> http://winpdb.org/
>
>> Yes. I don't have Windows except one one PC :P
>
> WinPDB runs on non-Windows platforms :)
>
One might reasonably argue that it has a pretty couter-intuitive name, then.

Jean-Michel Pichavant

unread,
Mar 15, 2010, 2:39:31 PM3/15/10
to Steve Holden, pytho...@python.org
Steve Holden wrote:

> pyt...@bdurham.com wrote:
>
>>>> Any reason you prefer PDB over WinPDB?
>>>> http://winpdb.org/
>>>>
>>> Yes. I don't have Windows except one one PC :P
>>>
>> WinPDB runs on non-Windows platforms :)
>>
>>
> One might reasonably argue that it has a pretty couter-intuitive name, then.
>
> regards
> Steve
>
'Win' may stand for Winner, not Windows :D

JM

Jean-Michel Pichavant

unread,
Mar 15, 2010, 2:41:18 PM3/15/10
to vsoler, pytho...@python.org
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

Jean-Michel Pichavant

unread,
Mar 15, 2010, 2:50:18 PM3/15/10
to Jean-Michel Pichavant, pytho...@python.org, vsoler
Jean-Michel Pichavant wrote:
> 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

0 new messages