Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #77793 > unrolled thread

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

Started byViet Nguyen <vhnguyenn@yahoo.com>
First post2014-09-11 22:15 -0700
Last post2014-09-12 06:39 -0700
Articles 3 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  Why command os.popen works in python interactive mode but not in script debugger mode? Viet Nguyen <vhnguyenn@yahoo.com> - 2014-09-11 22:15 -0700
    Re: Why command os.popen works in python interactive mode but not in script debugger mode? Chris Angelico <rosuav@gmail.com> - 2014-09-12 15:26 +1000
    Re: Why command os.popen works in python interactive mode but not in script debugger mode? Viet Nguyen <vhnguyenn@yahoo.com> - 2014-09-12 06:39 -0700

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

FromViet Nguyen <vhnguyenn@yahoo.com>
Date2014-09-11 22:15 -0700
SubjectWhy command os.popen works in python interactive mode but not in script debugger mode?
Message-ID<ce20cc54-7632-4928-a061-455d1bc11467@googlegroups.com>
Can anyone give me hint or reason why same command behaves differently in debugger mode from interactive mode:

From interactive mode:

>>> import os
>>> p = os.popen('date')
>>> p.read()
'Thu Sep 11 11:18:07 PDT 2014\n'

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?

Thanks,
Viet


[toc] | [next] | [standalone]


#77794

FromChris Angelico <rosuav@gmail.com>
Date2014-09-12 15:26 +1000
Message-ID<mailman.13957.1410499567.18130.python-list@python.org>
In reply to#77793
On Fri, Sep 12, 2014 at 3:15 PM, Viet Nguyen
<vhnguyenn@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

[toc] | [prev] | [next] | [standalone]


#77810

FromViet Nguyen <vhnguyenn@yahoo.com>
Date2014-09-12 06:39 -0700
Message-ID<1cc97a34-b21a-4681-b361-117dd4a352fc@googlegroups.com>
In reply to#77793
On Thursday, September 11, 2014 10:15:57 PM UTC-7, Viet Nguyen wrote:
> Can anyone give me hint or reason why same command behaves differently in debugger mode from interactive mode:
> 
> 
> 
> From interactive mode:
> 
> 
> 
> >>> import os
> 
> >>> p = os.popen('date')
> 
> >>> p.read()
> 
> 'Thu Sep 11 11:18:07 PDT 2014\n'
> 
> 
> 
> 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?
> 
> 
> 
> Thanks,
> 
> Viet

Thank you for your help.  That resolved the issue.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web