Why command os.popen works in python interactive mode but not in script debugger mode?

Chris Angelico rosuav at gmail.com
Fri Sep 12 01:26:04 EDT 2014


On Fri, Sep 12, 2014 at 3:15 PM, Viet Nguyen
<vhnguyenn at yahoo.com.dmarc.invalid> wrote:
> But from debugger mode in a script:
>>>> import os
> (Pdb) p = os.popen('date')
> *** SyntaxError: SyntaxError('invalid syntax', ('<string>', 1, 1, "= os.popen('date')"))
>
>
> Can anyone help me why there is syntax here?
>

This is actually a command to the debugger. You say "p
some_expression" and it prints out the value of some_expression.

https://docs.python.org/2/library/pdb.html#debugger-commands
""""
Commands that the debugger doesn’t recognize are assumed to be Python
statements and are executed in the context of the program being
debugged. Python statements can also be prefixed with an exclamation
point (!).
"""

So try this:

!p = os.popen('date')

ChrisA



More information about the Python-list mailing list