在 python 中使用另一个函数的结果
Use the result of a function in another on in python
如果您的 str() 或 list() 对象可能最终为空:astr = '' 或 list = [],那么您可能需要使用 list[-1:] 而不是 alist [-1] 对象“相同”。
some_list = [1, 2, 3]
some_list[-1] = 5 # Set the last element
some_list[-2] = 3 # Set the second to last element
some_list
a_list = ['zero', 'one', 'two', 'three']
a_list[-1]
'three'
您是要这样做吗:
duct_ret = Duct(0.4, 0.3, 10, 18, 19.5, 3, 1, 1010, 1.2)
#---- INPUT
#-- Geometry
import ENGINE as EN
duct_ret.c_s = EN.cross_section(duct_ret.width, duct_ret.height)
print(duct_ret.c_s)
print(EN.Tair_outlet(duct_ret.Ts_int, duct_ret.Tair_inlet, duct_ret.hint, duct_ret.c_s, duct_ret.v_air, duct_ret.rho_air, duct_ret.cp_air, duct_ret.L))
另一个更好的选择是:
class Duct:
def __init__(self, width, height, L, Tair_inlet, Ts_int, hint, v_air, cp_air, rho_air):
self.width = width
self.height = height
self.L = L
self.Tair_inlet = Tair_inlet
self.Ts_int = Ts_int
self.hint = hint
self.v_air = v_air
self.cp_air = cp_air
self.rho_air = rho_air
self.c_s = EN.cross_section(self.width, self.height)
duct_ret = Duct(0.4, 0.3, 10, 18, 19.5, 3, 1, 1010, 1.2)
print(duct_ret.c_s)
print(EN.Tair_outlet(duct_ret.Ts_int, duct_ret.Tair_inlet, duct_ret.hint, duct_ret.c_s, duct_ret.v_air, duct_ret.rho_air, duct_ret.cp_air, duct_ret.L))
如果您的 str() 或 list() 对象可能最终为空:astr = '' 或 list = [],那么您可能需要使用 list[-1:] 而不是 alist [-1] 对象“相同”。
some_list = [1, 2, 3]
some_list[-1] = 5 # Set the last element
some_list[-2] = 3 # Set the second to last element
some_list
a_list = ['zero', 'one', 'two', 'three']
a_list[-1]
'three'
您是要这样做吗:
duct_ret = Duct(0.4, 0.3, 10, 18, 19.5, 3, 1, 1010, 1.2)
#---- INPUT
#-- Geometry
import ENGINE as EN
duct_ret.c_s = EN.cross_section(duct_ret.width, duct_ret.height)
print(duct_ret.c_s)
print(EN.Tair_outlet(duct_ret.Ts_int, duct_ret.Tair_inlet, duct_ret.hint, duct_ret.c_s, duct_ret.v_air, duct_ret.rho_air, duct_ret.cp_air, duct_ret.L))
另一个更好的选择是:
class Duct:
def __init__(self, width, height, L, Tair_inlet, Ts_int, hint, v_air, cp_air, rho_air):
self.width = width
self.height = height
self.L = L
self.Tair_inlet = Tair_inlet
self.Ts_int = Ts_int
self.hint = hint
self.v_air = v_air
self.cp_air = cp_air
self.rho_air = rho_air
self.c_s = EN.cross_section(self.width, self.height)
duct_ret = Duct(0.4, 0.3, 10, 18, 19.5, 3, 1, 1010, 1.2)
print(duct_ret.c_s)
print(EN.Tair_outlet(duct_ret.Ts_int, duct_ret.Tair_inlet, duct_ret.hint, duct_ret.c_s, duct_ret.v_air, duct_ret.rho_air, duct_ret.cp_air, duct_ret.L))