无明显原因的“语法错误:无效语法" [英] 'Syntax Error: invalid syntax' for no apparent reason

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

问题描述

我一直在尝试修复,但找不到错误不断出现的原因.Pmin、Pmax、w、fi1 和 fi2 都已分配有限值

I've been trying to get a fix and can't find why the error keeps appearing. Pmin,Pmax,w,fi1 and fi2 have all been assigned finite values

guess=Pmin+(Pmax-Pmin)*((1-w**2)*fi1+(w**2)*fi2)

当我从代码中删除这一行时,同样的错误出现在下一行代码中,我也想不出任何原因

When i remove this line from the code, the same error appears at the next line of code, again for no reason I can think of

这是我所指的代码块:

def Psat(self, T):
    pop= self.getPborder(T)
    boolean=int(pop[0])

    P1=pop[1]
    P2=pop[2]
    if boolean:
        Pmin = float(min([P1, P2]))
        Pmax = float(max([P1, P2]))
        Tr=T/self.typeMolecule.Tc
        w=0.5*(1+scipy.tanh((10**5)*(Tr-0.6)))
        fi1=0.5*(1-scipy.tanh(8*((Tr**0.4)-1)))
        fi2=0.460*scipy.sqrt(1-(Tr-0.566)**2/(0.434**2)+0.494

        guess = Pmin+(Pmax-Pmin)*((1-w**2)*fi1+(w**2)*fi2)   #error here

        solution = scipy.optimize.newton(funcPsat,guess, args=(T,self))

推荐答案

对于在您认为正确的行上似乎是错误的问题,您通常可以删除/注释出现错误的行,并且,如果错误移动到下一行,有两种可能.

For problems where it seems to be an error on a line you think is correct, you can often remove/comment the line where the error appears to be and, if the error moves to the next line, there are two possibilities.

要么两行有问题,要么上一行有问题正在处理.最可能的情况是第二个选项(如果您删除另一行并再次移动,则更是如此).

Either both lines have a problem or the previous line has a problem which is being carried forward. The most likely case is the second option (even more so if you remove another line and it moves again).

例如以下 Python 程序 twisty_passages.py:

For example, the following Python program twisty_passages.py:

xyzzy = (1 +
plugh = 7

产生错误:

  File "twisty_passages.py", line 2
    plugh = 7
          ^
SyntaxError: invalid syntax

尽管问题明显在第 1 行.

despite the problem clearly being on line 1.

在您的特定情况下,就是问题.根据以下代码段,before 错误行中的括号不匹配:

In your particular case, that is the problem. The parentheses in the line before your error line is unmatched, as per the following snippet:

# open parentheses: 1  2             3
#                   v  v             v
fi2=0.460*scipy.sqrt(1-(Tr-0.566)**2/(0.434**2)+0.494
#                               ^             ^
# close parentheses:            1             2

根据您要实现的目标,解决方案可能就像在末尾添加另一个右括号一样简单,以关闭 sqrt 函数.

Depending on what you're trying to achieve, the solution may be as simple as just adding another closing parenthesis at the end, to close off the sqrt function.

我不能说确定,因为我不认识我头顶上的表情.如果(假设 PSAT 是酶,并且使用 typeMolecule 标识符)这与分子生物学有关,那就不足为奇了 - 我似乎记得我年轻时一直失败的生物学:-)

I can't say for certain since I don't recognise the expression off the top of my head. Hardly surprising if (assuming PSAT is the enzyme, and the use of the typeMolecule identifier) it's to do with molecular biology - I seem to recall failing Biology consistently in my youth :-)

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

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