Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I interact with rather long python scripts?

I love the IDLE. However, sometimes I have 100-200 line scripts and I want to sort of interactively debug/play with say, functions defined in foo.py instead of just calling python foo.py. Is there a way I can trigger IDLE in the context of my foo.py?

like image 661
meder omuraliev Avatar asked Apr 12 '26 07:04

meder omuraliev


2 Answers

Insert this line into the script:

import pdb; pdb.set_trace()

Which will start the python debugger which lets you step through the script interactively, checking variables and such as you go.

like image 192
Mizipzor Avatar answered Apr 18 '26 10:04

Mizipzor


I assume you are asking about how to enable debugging in Idle?

In the Python Shell window, choose Debugger from the Debug menu, then open foo.py and use the Run Model command. A Debug Control window opens, allowing you to step through the execution of foo.py; when execution is over, the prompt is still available for you to manually call functions, interact with objects or otherwise tinker with your application (and you will be still debugging the script).

like image 24
badp Avatar answered Apr 18 '26 09:04

badp



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!