语法错误:语法无效? [英] SyntaxError: invalid syntax?

查看:66
本文介绍了语法错误:语法无效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下午好,

我正在用 python 开发一个脚本,当我试图从终止符/终端编译它时,我总是收到这个错误,但我不明白语法错误在哪里?

I am developing a script in python and while I am trying to compile it from the terminator/terminal i always get this error, but I cannot understand where is the syntax error?

文件_case1.py",第 128 行

File "_case1.py", line 128

print ('########################')
    ^

语法错误:无效语法

然后我只是改变句子的位置,我得到的是..

Then I just change the position of the sentence and what I get is..

print '########################'
    ^

语法错误:无效语法

有什么问题?

推荐答案

检查 print 行之前的代码是否有错误.这可能是由前一行中的错误引起的;例如:

Check the code before the print line for errors. This can be caused by an error in a previous line; for example:

def x():
    y = [
    print "hello"
x()

这会产生以下错误:

  File "E:\Python\test.py", line 14
    print "hello"
        ^
SyntaxError: invalid syntax

当错误明显出现在它之前的行时,y = [.没有更多代码就很难调试,但是如果在打印行之前缺少一些括号或类似的东西,它可能会导致这样的错误.

When clearly the error is in the line before it, y = [. It's tough to debug without more code, but if you have some brackets missing before the print line or something similar it can cause such an error.

这篇关于语法错误:语法无效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆