2015-12-03 144 views
0

我的代码将接受来自用户界面的值,然后计算出密度,但是当我尝试调用我的函数“Properties”时,它告诉我Pressure2是未定义的。对不起,如果我的格式不好,这是我的第一篇文章。Python中的调用函数Spyder为UI

`def variables(self): #This Function gets the initial conditions from the UI 
    pressure1=self.ui.pressure1.value 
    pressure2=self.ui.pressure2.value 
    temp1=self.ui.temp1.value 
    temp2=self.ui.temp2.value 
    ` 

def properties(self): #This Function pulls values from array, when user picks the gas. 
    if self.ui.gas_2.findText('Oxygen'): 
     rc=elementsMap['Oxygen'][1] 
     gamma=elementsMap['Oxygen'][0] 
    elif self.ui.gas_2.findText('Helium'): 
     rc=elementsMap['Helium'][1] 
     gamma=elementsMap['Helium'][0] 
    elif self.ui.gas_2.findText('Hydrogen'): 
     rc=elementsMap['Hydrogen'][1] 
     gamma=elementsMap['Hydrogen'][0] 
    def instanous(self): # This function calculates the instanous density. 


    rho2=self.variables(pressure2)/(self.properties(rc)*self.variables(temp2)) 
    NameError: name 'pressure2' is not defined 

`

+0

答案就在你的错误之上。 – Mai

+0

错误发生在最后一行代码上。 “rho2”对不起,我没有说清楚。 –

+0

这就是答案。你把压力2放在未定义的地方。除此之外,你的代码在范围方面没有意义。在继续之前,您应该考虑查看一些教程或MOOC。 – Mai

回答

0

几个错误在你的代码:

  1. 你的代码需要一个类定义里面,因为你引用self
  2. self已经有了你想要的属性,所以没有必要将self中的属性复制到self。例如,当你需要pressure2时,你可以直接从self.ui.pressure2.value得到它。
  3. 从我看到的,你不需要一个对象。你需要一个tuple