1

In a Spyder iPython console:

print(sys.version)
3.6.1 |Anaconda 4.4.0 (64-bit)| (default, May 11 2017, 13:09:58) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)]

and in a Ubuntu GNOME terminal 3.18.3:

rappleto:~$ python
Python 3.6.1 |Anaconda 4.4.0 (64-bit)| (default, May 11 2017, 13:09:58) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux

so identical versions and builds of Python

In Spyder:

In [4]: with open("pid.cpp") as pidcpp:
   ...:     data=pidcpp.read()
   ...: print(data)
   ...: 
// pid.cpp - author: rappleto
#include <PID_v1.h>
...

in terminal:

>>> with open("pid.cpp") as pidcpp:
...     data=pidcpp.read()
... print(data)
  File "<stdin>", line 3
    print(data)
        ^
SyntaxError: invalid syntax

Is there some special way to end a "with" statement in the terminal?

rappleto
  • 11
  • 1
  • Interestingly, putting the `print` statement inside the `with` block seems to make things work fine, even though `with` blocks are not supposed to have a different scope (as far as I'm aware). – Zev Chonoles Sep 08 '17 at 19:26
  • [This answer on another post](https://stackoverflow.com/a/6432414/1090302) is possibly related. – Zev Chonoles Sep 08 '17 at 19:30
  • The `...` prompt means the interpreter is expecting you to add to the previous block (your `with` block). Add an extra newline before the `print` and it should run the `with` block and bring you back to the `>>>` prompt, where you can proceed with the `print`. (At least in the standard python interactive interpreter... I've never used Spyder and can't speak to its prompts.) – glibdud Sep 08 '17 at 19:33
  • In Python's built-in prompt, you have to terminate a multi-line statement by entering a blank line, before you can start a new top-level (unindented) statement. This has nothing specifically to do with the `with` statement. – jasonharper Sep 08 '17 at 19:35
  • @jasonharper and glibdud: Seems like you're right! – Zev Chonoles Sep 08 '17 at 19:40

0 Answers0