Search code examples
pythonread-eval-print-looppdb

How do I enter Python code in PDB without having it interpreted as a command?


Sometimes I want to type Python code in PDB, if that code happens to start with a PDB command, you'll get an error

(Pdb) list()
*** Error in argument: '()'

How do I avoid this? It's sometimes surprising because I haven't memorized all 40-ish commands and their short forms and my code will just error.


Solution

  • You prefix them with !:

    (Pdb) !list()
    []
    

    https://docs.python.org/3/library/pdb.html#pdbcommand-!