简体   繁体   English

Python 打印语法无效

[英]Python invalid syntax in print

Sorry I am not familar with Python...对不起,我不熟悉 Python...

It gives me the following error message它给了我以下错误信息

  File "gen_compile_files_list.py", line 36
    print 'java files:', n_src
                      ^
SyntaxError: invalid syntax

Ie caret points to last quote.即插入符号指向最后引用。 What's wrong with it?它出什么问题了?

OS Windows 7, Python version 3.2.2操作系统 Windows 7、Python 版本 3.2.2

On Python 3, print is a function .在 Python 3 上, 打印出一个 function You need this:你需要这个:

print('java files:', n_src)

print changed syntax between Python2 and Python3;打印 Python2 和 Python3 之间更改的语法; it is now a function . 现在是 function

You would need to change:您需要更改:

 print 'java files:', n_src

to

 print('java files:', n_src)

Alternatively, you can try converting the code from Python2 to Python3 syntax with the 2to3 tool.或者,您可以尝试使用 2to3 工具将代码从 Python2 语法转换为 Python3 语法。 Here is more information on the transition if you are interested.如果您有兴趣,这里有更多关于过渡的信息 This way you can maintain a single code base that works on both versions.这样您就可以维护一个适用于两个版本的代码库。

As you are not familiar with python, try installing Python 2 instead and running the code with that.由于您不熟悉 python,请尝试安装 Python 2 并使用它运行代码。

print is a function in Python 3+. print是 Python 3+ 中的 function。 So:所以:

print ('java files:', n_src)

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

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