语法错误:语法无效,没有明显的原因。

时间:2021-12-04 22:53:32

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

我一直在试图找到一个解决方法,却找不到错误持续出现的原因。Pmin,Pmax,w,fi1和fi2都被分配了有限值。

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

当我从代码中删除这一行时,同样的错误会出现在下一行代码中,这也是我所能想到的。

Edit: Here is the chunk of code I was referring to: def Psat(self, T):

编辑:这里是我所指的代码块: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))

2 个解决方案

#1


34  

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).

这两行都有问题,或者前面的行有问题。最有可能的情况是第二个选项(如果删除另一行,它会再次移动)。

For example, the following Python program twisty_passages.py:

例如,下面的Python程序twisty_passages.py:

xyzzy = (1 +
plugh = 7

generates the error:

生成错误:

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

despite the problem clearly being on line 1.

尽管问题明显在第1行。


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

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.

根据您想要实现的内容,解决方案可能非常简单,只需在末尾添加另一个闭括号,以关闭sqrt函数。

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 :-)

我不能肯定地说,因为我没有意识到我头顶上的表情。如果(假设PSAT是一种酶,并使用了这种类型的分子标识符)这与分子生物学有关,这一点也不奇怪——我似乎在年轻时就一直记得失败的生物学:-)

#2


2  

You're missing a close paren in this line:

在这一行里,你错过了一个亲密的伙伴:

fi2=0.460*scipy.sqrt(1-(Tr-0.566)**2/(0.434**2)+0.494

There are three ( and only two ).
I hope This will help you.

有三个(也只有两个)。我希望这对你有帮助。

#1


34  

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).

这两行都有问题,或者前面的行有问题。最有可能的情况是第二个选项(如果删除另一行,它会再次移动)。

For example, the following Python program twisty_passages.py:

例如,下面的Python程序twisty_passages.py:

xyzzy = (1 +
plugh = 7

generates the error:

生成错误:

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

despite the problem clearly being on line 1.

尽管问题明显在第1行。


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

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.

根据您想要实现的内容,解决方案可能非常简单,只需在末尾添加另一个闭括号,以关闭sqrt函数。

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 :-)

我不能肯定地说,因为我没有意识到我头顶上的表情。如果(假设PSAT是一种酶,并使用了这种类型的分子标识符)这与分子生物学有关,这一点也不奇怪——我似乎在年轻时就一直记得失败的生物学:-)

#2


2  

You're missing a close paren in this line:

在这一行里,你错过了一个亲密的伙伴:

fi2=0.460*scipy.sqrt(1-(Tr-0.566)**2/(0.434**2)+0.494

There are three ( and only two ).
I hope This will help you.

有三个(也只有两个)。我希望这对你有帮助。