0

I am newly converting to Python and want to know how to stop or pause in a script for diagnostic purposes. For instance, I want to do something like:

If Condition_is_True:
     Statement
 else:
     print('Condition not met!')
     stop 

I guess I can use the try: except: statement, but the condition won't raise an exception; or I can use a while statement, but it won't stop.

I knew I could also use the debugger (import pdb; pdb.set_trace()), but I don't want to keep the debugger in the code permanently. Is there a better way to do this?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
astromz
  • 11
  • 3
  • Are you asking for a *Python debugger*? – deceze Mar 17 '15 at 11:51
  • No, not really. Using a python debugger is one way to do this, I guess. But I am wondering if there is a way to just stop the script and notify me that the condition is not met. – astromz Mar 17 '15 at 11:54
  • 1
    Use an IDE. Pycharm works like a charm – biobirdman Mar 17 '15 at 12:05
  • *"Using a python debugger is one way to do this"* - no, it is **the way** to do this. If you want to stop and inspect running code, you need a debugger (not necessarily `pdb`; the duplicate has several answers with other options). FWIW, +1 for @biobirdman's PyCharm recommendation. – jonrsharpe Mar 17 '15 at 12:09
  • `if ..: print('met'); exit()`...!? – deceze Mar 17 '15 at 12:12

0 Answers0