Python“with statement”在控制台中工作,但在Ubuntu终端中不起作用

时间:2017-09-08 19:19:01

标签: python-3.x ubuntu

在Spyder iPython控制台中:

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)]

,在Ubuntu GNOME终端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

如此相同的Python版本和构建

在Spyder中:

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

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

是否有一些特殊方法可以在终端中结束“with”语句?

0 个答案:

没有答案