简体   繁体   English

如何使用 Python 中的打印修复此语法错误?

[英]How do I fix this syntax error with print in Python?

I copied the Python code that Google Cloud recommends.我复制了 Google Cloud 推荐的 Python 代码。 I've tried it in Jupyter Notebook and as a Python file but I still get the syntax error:我已经在Jupyter Notebook和 Python 文件中尝试过,但我仍然收到语法错误:

def predict(content, project_id, model_id):
    # More code.
    pass

print predict("1.jpg", ispace-254720,  ICN886814670746214838)

Gives:给出:

  File "<ipython-input-16-a9c7141e2bf3>", line 1
    print predict("1.jpg", ispace-254720,  ICN886814670746214838)
                ^
SyntaxError: invalid syntax

It's probably old Python 2.7 code.它可能是旧的 Python 2.7 代码。 I'm guessing you're using Python 3, in which case print is now a function, so you need to put parentheses after print :我猜你正在使用 Python 3,在这种情况下print现在是 function,所以你需要在print后面加上括号:

print(predict("1.jpg", ispace-254720,  ICN886814670746214838))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM