python - TypeError:FUNCTION NAME () 缺少 1 个必需的位置参数:'v_air
问题描述
我有两个问题:
- 当我调用函数时,Python 说我错过了函数 simple_friction_method 的一个位置参数,但所有参数都写在上面。
如果您的 str() 或 list() 对象可能最终为空:astr = '' 或 alist = [],那么您可能希望使用 alist[-1:] 而不是 alist[-1] for object "同一性”。
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'
解决方案
看,你基本上已经做对了,但只是为了记录,这里是工作代码:
import numpy as np
from scipy.optimize import root
def viscosity(Tair_inlet):
mu=(1.458*(10**-6)*(Tair_inlet+ 273.15)**1.5)/((Tair_inlet+ 273.15)+110.4)
return mu
def per_circ(D_1):
p_c = np.pi*(D_1)
return p_c
def Tair_outlet(Ts_int,Tair_inlet, hint, p_c, v_air, rho_air, cp_air, L ):
k = hint/(p_c*v_air*rho_air*cp_air)
Tair_outlet = Ts_int + (Tair_inlet-Ts_int)*np.exp(-k*L)
return Tair_outlet
def simplified_friction_method(V_dot, rho_air , L, mu, delta_P, v_air, epsilon ):
m_dot = V_dot * rho_air
print('m_dot',m_dot, '[kgs^-1]')
D_0 = (4*m_dot/(np.pi*rho_air*v_air))**(1/2)
D_1 = D_0
print('D_0',D_0, '[m]')
Re = (v_air * D_0 * rho_air) / mu
print('Re', Re )
f_0= 0*D_0
f_0 = (-2*np.log((epsilon/D_0)/3.7065))**-2
print('f_0', f_0,)
delta_P_tot = delta_P*L
f_1 = f_0
f_2 = 0
e =np.ones(D_0.size)
print("e",e)
while e.any() > 0.0001:
D_1 = ((f_1 * L)/delta_P_tot )* rho_air *(v_air)**2
print('D_1', D_1, '[m]')
Re = (v_air * D_1 * rho_air) / mu
f_2=(-2*abs(np.log((epsilon/D_1)/3.7065 + 2.5226/(Re*np.sqrt(f_1)))))**-2
e = abs(f_1-f_2)
print('e', e, )
f_1 = f_2
return('D_1', D_1,'Re', Re,'f', f_2,'e', e )
class Duct:
def __init__(
self, Tair_inlet, Ts_int, hint, cp_air, rho_air, Rstar, epsilon
):
self.Tair_inlet = Tair_inlet
self.Ts_int = Ts_int
self.hint = hint
self.cp_air = cp_air
self.rho_air = rho_air
self.Rstar = Rstar
self.epsilon = epsilon
duct_ret = Duct(18, 19.5, 3, 1010, 1.2, 8324.68/29, 0.2/1000)
duct_circ = Duct(18, 19.5, 3, 1010, 1.2, 8324.68/29, 0.2/1000)
duct_ret.L = 8
duct_circ.L = np.array([[10, 8, 10, 8]])
duct_circ.V_dot = np.array([[3, 1, 2, 1]])
duct_circ.v_air = np.array([[5, 3, 5, 3]])
duct_circ.deltaP = 1
duct_circ.mu = viscosity(duct_circ.Tair_inlet)
print(duct_circ.mu)
duct_circ.D_1 = simplified_friction_method(
duct_circ.rho_air, duct_circ.V_dot, duct_circ.L, duct_circ.mu,
duct_circ.deltaP, duct_circ.v_air, duct_circ.epsilon
)
print(duct_circ.D_1)
请注意,由于我没有两个文件,因此我不导入EN
,因此删除EN.
了函数调用前面的。我还将epsilon
参数添加到Duct
您的版本中缺少的类并将其传递给simplified_friction_method
函数。有很多方法可以改进代码,但现在我认为更重要的是它可以工作并且你理解它。您显然并不真正了解 Classes 是如何工作的,所以我建议您研究一下。
推荐阅读
- java - 如何打开 Play 商店以显示给定其自定义 url 方案的应用程序?
- javascript - 你可以使用 Nodejs 的 Create-React-App npm start 吗?
- android - 提供捆绑包和 APK 时如何删除 APK
- pytorch - CUDA 错误 59:触发了设备端断言
- python - 用于模板匹配的 Python OpenCV
- python - PRAW:你是怎么得到你的提交链接的?
- c# - 您如何通过共同属性将两个自定义对象相互比较?
- php - 延迟睡眠时遇到问题
- nativescript - 获取 ios [Nativescript] 的新构建错误
- c# - 在 C# 中调用自身内部的方法