1

Can I ask IPython to break when it encounters a variable at a specific value?

myloop.py

for myvar in range(1, 10):
    print("myvar: {}".format(myvar))

this does not work, but I envision something like...

%run -d -b myvar:6 /path/to/myloop.py

where IPython breaks when myvar is 6

There is a similar question using import ipdb;ipdb.set_trace() but based on IPython's %run all necessary input to debug a condition can be handled using the magic command.

Stuber
  • 447
  • 5
  • 16
  • I have provided an answer below, if my answer has helped you and you think it will help others who may follow this question please mark my answer as accepted. – Jamie Lindsey Nov 12 '18 at 00:41
  • Possible duplicate of [pdb/ipdb for python break on editable condition](https://stackoverflow.com/questions/17280575/pdb-ipdb-for-python-break-on-editable-condition) – soundstripe Nov 12 '18 at 01:16

1 Answers1

0

This is very simple:

for myvar in range(1, 10):
    if myvar == 6:
        print("myvar: {}".format(myvar))
Jamie Lindsey
  • 928
  • 14
  • 26
  • This would require internal edits, which would be slow to add and cause unnecessary changes in version control. Looking for a solution using %run. – Stuber Nov 12 '18 at 12:16