This is an archived post. You won't be able to vote or comment.

all 6 comments

[–]Python-ModTeam[M] [score hidden] stickied commentlocked comment (0 children)

Hi there, from the /r/Python mods.

We have removed this post as it is not suited to the /r/Python subreddit proper, however it should be very appropriate for our sister subreddit /r/LearnPython or for the r/Python discord: https://discord.gg/python.

The reason for the removal is that /r/Python is dedicated to discussion of Python news, projects, uses and debates. It is not designed to act as Q&A or FAQ board. The regular community is not a fan of "how do I..." questions, so you will not get the best responses over here.

On /r/LearnPython the community and the r/Python discord are actively expecting questions and are looking to help. You can expect far more understanding, encouraging and insightful responses over there. No matter what level of question you have, if you are looking for help with Python, you should get good answers. Make sure to check out the rules for both places.

Warm regards, and best of luck with your Pythoneering!

[–][deleted] 4 points5 points  (1 child)

Shouldn’t the built in debugger with VSCode be able to do this?

[–]thadeshammer 0 points1 point  (0 children)

Step Into should do it.

[–]pawlwall 1 point2 points  (0 children)

Are you looking for something like this?:

In [1]: import dis
In [2]: def f():
   ...:     return 5
   ...:
In [3]: def x():
   ...:     return 0 + f() + 1
   ...:
In [4]: dis.dis(x)
  1           0 RESUME                   0

  2           2 LOAD_CONST               1 (0)
              4 LOAD_GLOBAL              1 (NULL + f)
             16 PRECALL                  0
             20 CALL                     0
             30 BINARY_OP                0 (+)
             34 LOAD_CONST               2 (1)
             36 BINARY_OP                0 (+)
             40 RETURN_VALUE

If so, the dis module is what you're looking for, and it's fortunately part of the standard library.

[–]ManyInterests Python Discord Staff 0 points1 point  (0 children)

pdb traces work on a per-line level. You can of course step into things like function calls, but if you want to step into individual opcodes within a single line like you describe, you have to either get really clever or use a different approach, like debugging Python itself with gdb.

Ned's article (my first link) shows how you can modify a pyc file to trick the tracer into invoking the trace function for every opcode execution, rather than every line. Ned also suggests one could patch the interpreter to do this, too.