[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

"Breaking" the __main__ script

vsoler

3/14/2010 11:35:00 AM

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
15 Answers

Mark Lawrence

3/14/2010 11:53:00 AM

0

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

Michael Rudolf

3/14/2010 12:20:00 PM

0

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/librar...

HTH,
Michael

Steve Holden

3/14/2010 1:07:00 PM

0

Mark Lawrence wrote:
> vsoler wrote:
>> 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.

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://pyco...
Holden Web LLC http://www.hold...
UPCOMING EVENTS: http://holdenweb.event...

Joaquin Abian

3/14/2010 2:03:00 PM

0

On 14 mar, 12:34, vsoler <vicente.so...@gmail.com> wrote:
> 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

python

3/14/2010 3:04:00 PM

0

Michael,

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

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

Thanks,
Malcolm

Tim Chase

3/14/2010 6:31:00 PM

0

python@bdurham.com wrote:
>> Or you could use a real debugger, like pdb
>> http://docs.python.org/librar...
>
> Any reason you prefer PDB over WinPDB?
> http://w...

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

3/14/2010 7:35:00 PM

0

Am 14.03.2010 16:03, schrieb python@bdurham.com:
> Any reason you prefer PDB over WinPDB?
> http://w...

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

python

3/14/2010 8:08:00 PM

0

>> Any reason you prefer PDB over WinPDB?
>> http://w...

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

WinPDB runs on non-Windows platforms :)

Malcolm

Joaquin Abian

3/14/2010 8:11:00 PM

0

On 14 mar, 20:35, Michael Rudolf <spamfres...@ch3ka.de> wrote:
> Am 14.03.2010 16:03, schrieb pyt...@bdurham.com:
>
> > Any reason you prefer PDB over WinPDB?
> >http://w...
>
> Yes. I don't have Windows except one one PC :P

WinPdb is crossplatform. Is build with

Joaquin Abian

3/14/2010 8:18:00 PM

0

On 14 mar, 20:35, Michael Rudolf <spamfres...@ch3ka.de> wrote:
> Am 14.03.2010 16:03, schrieb pyt...@bdurham.com:
>
> > Any reason you prefer PDB over WinPDB?
> >http://w...
>
> 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