IPython 笔记本图片加载语法
IPython Notebook image loading syntax
我正在使用这个 Coursera course on linear algebra,它是基于 Python 的。我什至在 IP Notebook 上绘制了一些初始图并处理了复数。我用的是Windows,笔记本的显示是Chrome。
我得到了一个在绘图上调用jpeg图像的命令,指导员写的行是:
from image import *
我收到以下错误消息:
In [7]: from image import *
File "image.py", line 98
print("Hit Enter once the image is displayed.... ", end="")
^
SyntaxError: invalid syntax
我认为该调用可能指向从 this site 下载的 image.py
。
在我看来,代码是为 Python 3 设计的,并使用了 Python 的 print
函数。 Anaconda 提供 Python 3,所以请尝试使用它——我可以通过这种方式导入图像。
我使用Python2时SyntaxError的准确位置在这里:
File "image.py", line 98
print("Hit Enter once the image is displayed.... ", end="")
^
SyntaxError: invalid syntax
这是因为 Python2 正在尝试打印值元组,但它为元组获取的第二个元素是一个赋值。
The docs 为你的 Coursera 课程提示你这个(虽然它看起来并不明显)并警告你使用 Python 3 而不是 Python 2.
我会假设他们在课程中使用 python 3,所以你得到的错误是因为打印功能。
from image import *
File "image.py", line 98
print("Hit Enter once the image is displayed.... ", end="")
^
SyntaxError: invalid syntax
要么使用 Python 3,要么 from __future__ import print_function
我正在使用这个 Coursera course on linear algebra,它是基于 Python 的。我什至在 IP Notebook 上绘制了一些初始图并处理了复数。我用的是Windows,笔记本的显示是Chrome。
我得到了一个在绘图上调用jpeg图像的命令,指导员写的行是:
from image import *
我收到以下错误消息:
In [7]: from image import *
File "image.py", line 98
print("Hit Enter once the image is displayed.... ", end="")
^
SyntaxError: invalid syntax
我认为该调用可能指向从 this site 下载的 image.py
。
在我看来,代码是为 Python 3 设计的,并使用了 Python 的 print
函数。 Anaconda 提供 Python 3,所以请尝试使用它——我可以通过这种方式导入图像。
我使用Python2时SyntaxError的准确位置在这里:
File "image.py", line 98
print("Hit Enter once the image is displayed.... ", end="")
^
SyntaxError: invalid syntax
这是因为 Python2 正在尝试打印值元组,但它为元组获取的第二个元素是一个赋值。
The docs 为你的 Coursera 课程提示你这个(虽然它看起来并不明显)并警告你使用 Python 3 而不是 Python 2.
我会假设他们在课程中使用 python 3,所以你得到的错误是因为打印功能。
from image import *
File "image.py", line 98
print("Hit Enter once the image is displayed.... ", end="")
^
SyntaxError: invalid syntax
要么使用 Python 3,要么 from __future__ import print_function