Pea*_*lip 25 python syntax-error spyder
我一直试图修复,无法找到错误不断出现的原因.Pmin,Pmax,w,fi1和fi2都被赋予了有限值
guess=Pmin+(Pmax-Pmin)*((1-w**2)*fi1+(w**2)*fi2)
Run Code Online (Sandbox Code Playgroud)
当我从代码中删除此行时,在下一行代码中出现相同的错误,再次无缘无故我能想到
编辑:这是我所指的代码块:
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))
Run Code Online (Sandbox Code Playgroud)
pax*_*blo 64
对于您认为正确的线路上的错误似乎是正确的问题,您通常可以删除/注释出现错误的行,如果错误移动到下一行,则有两种可能性.
无论哪种都行有问题或先前的线具有正被结转的问题.最可能的情况是第二种选择(如果你移除另一条线并再次移动则更是如此).
例如,以下Python程序twisty_passages.py:
xyzzy = (1 +
plugh = 7
Run Code Online (Sandbox Code Playgroud)
生成错误:
File "twisty_passages.py", line 2
plugh = 7
^
SyntaxError: invalid syntax
Run Code Online (Sandbox Code Playgroud)
尽管问题显然在第1行.
在您的特定情况下,这就是问题所在.错误行之前的行中的括号是不匹配的,如下面的代码段所示:
# 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
Run Code Online (Sandbox Code Playgroud)
根据您要实现的目标,解决方案可能就像在最后添加另一个右括号一样简单,以关闭该sqrt功能.
我不能肯定地说,因为我不认识到我头脑中的表情.如果(假设PSAT是酶,并使用typeMolecule标识符)它与分子生物学有关 - 我似乎记得在我年轻时始终不及生物学:-)
小智 6
您在此行中缺少一个关闭括号:
fi2=0.460*scipy.sqrt(1-(Tr-0.566)**2/(0.434**2)+0.494
Run Code Online (Sandbox Code Playgroud)
有三个(而且只有两个)。
我希望这能帮到您。