简体   繁体   English

Python错误 - 语法无效

[英]Python error - Invalid syntax

I'm new to python and programming, I have a task to run the following file: http://pastebin.com/UmheVyvV with Python, but I get error on line 163: 我是python和编程的新手,我有一个任务来运行以下文件: http : //pastebin.com/UmheVyvV与Python,但我在第163行得到错误:

line 163
print filename + " "*(80 - len(filename) - len(ln)) + ln + delim,

SyntaxError: invalid syntax

There's a '^' below filename in the error message. 错误消息中的文件名下面有一个'^'。

Could anyone tell me how to solve this problem and be able to run the file? 谁能告诉我如何解决这个问题,并能够运行该文件? Thanks! 谢谢!

Replace < with ( : 替换< with (

print filename + " "*(80 - len(filename) - len(ln)) + ln + delim,
#                    ^

UPDATE UPDATE

The code in the given url is written for Python 2.x. 给定URL中的代码是为Python 2.x编写的。 It will not work in Python 3.x. 它不适用于Python 3.x.

If you are using python 3. the print statement become a function so you need to put parentheses. 如果您使用的是python 3. print语句将成为一个函数,因此您需要放置括号。 example: 例:

print (1+3)

The '^' shows you where the syntax is incorrect. '^'显示语法不正确的位置。 Depending on python version parenthesis should be used. 根据python版本,应使用括号。

doc http://docs.python.org/2/tutorial/errors.html doc http://docs.python.org/2/tutorial/errors.html

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

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