我想将 python 脚本 (x) 中的函数返回的属性之一用于 python 脚本 (y)
两个脚本之间的通信运行良好;我可以获取函数和属性,但不允许我获取函数返回的属性。
这是我的工作方式:
x.py
def func():
b = 10
a = 15
return [a,b]
c = 20
y.py
from x import func
import x
print (x.c)
print (func.b)
我得到“c”值和以下错误 AttributeError: 'function' object has no attribute 'b'
我也尝试过打印 x.b
,但我遇到了 AttributeError: module 'WorkingLSTM' has no attribute 'b'
提前致谢
最佳答案
调用 func 的方法是使用 func()
,它会给你 [a,b]。
例子:
funcResult = func()
a = funcResult[0]
b = funcResult[1]
funcResults 是func() 的返回值,即列表[a,b]。
关于python - 无法在另一个python脚本中使用python函数的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58132861/