缺少必需的参数 - 'NoneType' 对象不可订阅
missing required argument - 'NoneType' object is not subscriptable
我有一些 Python 代码,编译时有错误:
def rad2_cv(m, n, c, type, x):
eps = 10e-8;
if type == 1:
result = f_radial.rad_fun(0, m, n, c, x, eps)
return result[2], result[3]
elif type == -1:
result = f_radial.rad_fun(1, m, n, c, x, eps)
return result[2], result[3]
和 .f
文件中的一些 Fortran 代码,编译无误:
c****************************************************************************
c Radial spheroidal functions
c
c parameters:
c kob - switch between prolate (0) and oblate (1) functions
c m - index m
c ne - maximum index n
c c2 - argument c (complex*16)
c ksi0 - argument xi (real*8)
c eps - accuracy of getting eigenvalues
c
c results (all complex*16):
c R1f(ne) - functions R^(1)_mn (c,xi), n = 1, ne
c R1d(ne) - derivatives dR^(1)_mn (c,xi)/dxi, n = 1, ne
c R2f(ne) - functions R^(2)_mn (c,xi), n = 1, ne
c R2d(ne) - derivatives dR^(2)_mn (c,xi)/dxi, n = 1, ne
c
c 2005, Nov
c****************************************************************************
SUBROUTINE rad_fun (kob, m, ne, C2, KSI0, EPS, R1f, R1d, R2f,R2d)
parameter (nterms=330)
IMPLICIT REAL*8 (A-H,O-Q,T-Z), COMPLEX*16 (R-S)
REAL*8 C2, ksi0
complex*16 R1f , R1d , R2f , R2d
COMPLEX*16 bdc2
DIMENSION RLC2(nterms), rDC2(4*nterms), bDC2(4*nterms)
COMMON /K1/ S, S1, AKSI, AK, K, NK, nal
COMMON /EPS1/ EPS1
COMMON /EPS33/ EPS33
COMMON /EPS3/ EPS3
COMMON /FACT/ FACT(300)
COMMON /PI/ PI
cf2py intent(in) kob, m, ne, C2, KSI0, EPS
cf2py intent(out) R1f, R1d, R2f, R2d
…
c final results
c 5 continue
5 R1f = r1
R1d = r2
R2f = r3
R2d = r4
1 CONTINUE
RETURN
END
当我尝试编译 Python 代码时出现 2 个错误:
第一个错误:
f_radial.rad_fun() missing required argument 'r1f' (pos 7)
在
result = f_radial.rad_fun(0, m, n, c, x, eps)
和第二个错误:
'NoneType' object is not subscriptable
在
return result[2], result[3]
我该怎么办?
问题已解决,因为在 COMMON
语句之前替换了 cf2py intent...
语句。
SUBROUTINE rad_fun (kob, m, ne, C2, KSI0, EPS, R1f, R1d, R2f,R2d)
parameter (nterms=330)
IMPLICIT REAL*8 (A-H,O-Q,T-Z), COMPLEX*16 (R-S)
REAL*8 C2, ksi0
complex*16 R1f , R1d , R2f , R2d
COMPLEX*16 bdc2
DIMENSION RLC2(nterms), rDC2(4*nterms), bDC2(4*nterms)
cf2py intent(in) kob, m, ne, C2, KSI0, EPS
cf2py intent(out) R1f, R1d, R2f, R2d
COMMON /K1/ S, S1, AKSI, AK, K, NK, nal
COMMON /EPS1/ EPS1
COMMON /EPS33/ EPS33
COMMON /EPS3/ EPS3
COMMON /FACT/ FACT(300)
COMMON /PI/ PI
…
我有一些 Python 代码,编译时有错误:
def rad2_cv(m, n, c, type, x):
eps = 10e-8;
if type == 1:
result = f_radial.rad_fun(0, m, n, c, x, eps)
return result[2], result[3]
elif type == -1:
result = f_radial.rad_fun(1, m, n, c, x, eps)
return result[2], result[3]
和 .f
文件中的一些 Fortran 代码,编译无误:
c****************************************************************************
c Radial spheroidal functions
c
c parameters:
c kob - switch between prolate (0) and oblate (1) functions
c m - index m
c ne - maximum index n
c c2 - argument c (complex*16)
c ksi0 - argument xi (real*8)
c eps - accuracy of getting eigenvalues
c
c results (all complex*16):
c R1f(ne) - functions R^(1)_mn (c,xi), n = 1, ne
c R1d(ne) - derivatives dR^(1)_mn (c,xi)/dxi, n = 1, ne
c R2f(ne) - functions R^(2)_mn (c,xi), n = 1, ne
c R2d(ne) - derivatives dR^(2)_mn (c,xi)/dxi, n = 1, ne
c
c 2005, Nov
c****************************************************************************
SUBROUTINE rad_fun (kob, m, ne, C2, KSI0, EPS, R1f, R1d, R2f,R2d)
parameter (nterms=330)
IMPLICIT REAL*8 (A-H,O-Q,T-Z), COMPLEX*16 (R-S)
REAL*8 C2, ksi0
complex*16 R1f , R1d , R2f , R2d
COMPLEX*16 bdc2
DIMENSION RLC2(nterms), rDC2(4*nterms), bDC2(4*nterms)
COMMON /K1/ S, S1, AKSI, AK, K, NK, nal
COMMON /EPS1/ EPS1
COMMON /EPS33/ EPS33
COMMON /EPS3/ EPS3
COMMON /FACT/ FACT(300)
COMMON /PI/ PI
cf2py intent(in) kob, m, ne, C2, KSI0, EPS
cf2py intent(out) R1f, R1d, R2f, R2d
…
c final results
c 5 continue
5 R1f = r1
R1d = r2
R2f = r3
R2d = r4
1 CONTINUE
RETURN
END
当我尝试编译 Python 代码时出现 2 个错误:
第一个错误:
f_radial.rad_fun() missing required argument 'r1f' (pos 7)
在
result = f_radial.rad_fun(0, m, n, c, x, eps)
和第二个错误:
'NoneType' object is not subscriptable
在
return result[2], result[3]
我该怎么办?
问题已解决,因为在 COMMON
语句之前替换了 cf2py intent...
语句。
SUBROUTINE rad_fun (kob, m, ne, C2, KSI0, EPS, R1f, R1d, R2f,R2d)
parameter (nterms=330)
IMPLICIT REAL*8 (A-H,O-Q,T-Z), COMPLEX*16 (R-S)
REAL*8 C2, ksi0
complex*16 R1f , R1d , R2f , R2d
COMPLEX*16 bdc2
DIMENSION RLC2(nterms), rDC2(4*nterms), bDC2(4*nterms)
cf2py intent(in) kob, m, ne, C2, KSI0, EPS
cf2py intent(out) R1f, R1d, R2f, R2d
COMMON /K1/ S, S1, AKSI, AK, K, NK, nal
COMMON /EPS1/ EPS1
COMMON /EPS33/ EPS33
COMMON /EPS3/ EPS3
COMMON /FACT/ FACT(300)
COMMON /PI/ PI
…