我不熟悉对象和类的概念;我想知道是否有更好的方法来访问方法的输出并将其传递给另一个方法?
class cafec_param:
def __init__(self,precip,pe,awc,nmonths):
self.precip = precip
self.pe = pe
self.awc = awc
self.nmonths = nmonths
def AWC(self):
if self.awc<254:
Ss = self.awc
Su = 0
else:
Ss = 254; Su = self.awc-254
AWC = Ss + Su
return AWC,Ss,Su
def test(self):
p = cafec_param.AWC(self)[0]
return p
有什么可能的方法将Ss和Su传递给另一种方法? 谢谢
答案 0 :(得分:0)
您可以从AWC内部调用所述方法:
<asp:TextBox ID="txtPaymentDate" runat="server"></asp:TextBox>
<script>
window.onload = function () {
$("#<%=txtPaymentDate.ClientID%>").datepicker({
autoclose: true,
dateFormat: "dd/mm/yy"
});
}
</script>
或在调用AWC的代码中获取AWC的输出,然后将Ss和Su传递给您的方法:
def AWC(self):
if self.awc<254:
Ss = self.awc
Su = 0
else:
Ss = 254; Su = self.awc-254
AWC = Ss + Su
this.your_method(Ss, Su)
return AWC,Ss,Su
请注意,我使用了您指定的类,方法和变量的名称,以使答案更易于理解。但是,您可能应该看看Python's naming conventions,以使您的代码更具可读性,更易于理解和维护。
希望我能帮上忙! :)
答案 1 :(得分:0)
在类中另一个方法内调用方法的更好方法。
class cafec_param:
def __init__(self,precip,pe,awc,nmonths):
self.precip = precip
self.pe = pe
self.awc = awc
self.nmonths = nmonths
def AWC(self):
if self.awc<254:
Ss = self.awc
Su = 0
else:
Ss = 254; Su = self.awc-254
AWC = Ss + Su
return AWC,Ss,Su
def test(self):
return self.AWC()[0]
ee=cafec_param('re',34,56,2)
print(ee.test())