How do I manipulate a variable whose name conflicts with PDB commands?

后端 未结 4 856
离开以前
离开以前 2020-12-23 15:39

My code is, for better or worse, rife with single letter variables (it\'s physics stuff, so those letters are meaningful), as well as NumPy\'s, which I\'m often interacting

4条回答
  •  Happy的楠姐
    2020-12-23 16:15

    Use an exclamation mark ! before a statement to have it run :

    python -m pdb test.py
    > /home/user/test.py(1)()
    -> print('foo')
    (Pdb) !n = 77
    (Pdb) !n
    77
    (Pdb) n
    foo
    > /home/user/test.py(2)()
    -> print('bar')
    (Pdb)
    

    The docs say:

    ! statement

    Execute the (one-line) statement in the context of the current stack frame. The exclamation point can be omitted unless the first word of the statement resembles a debugger command. [...]

提交回复
热议问题