Search code examples
pythondebuggingpdb

Python debugger convenience variable throws syntax error


I read in the Pdb documentation that

To set a temporary global variable, use a convenience variable. A convenience variable is a variable whose name starts with $. For example, $foo = 1 sets a global variable $foo which you can use in the debugger session.

And this is what happens when I put the $ sign before a variable name:

>>> breakpoint()
--Return--
> <stdin>(1)<module>()->None
(Pdb) $foo = 3
*** SyntaxError: invalid syntax

Why am I getting the error here?


Solution

  • Convenience variables were added in Python 3.12, if you're using an older version you can't use them