python - 无法在另一个python脚本中使用python函数的属性

标签 python function join ipc

我想将 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]

funcResultsfunc() 的返回值,即列表[a,b]

关于python - 无法在另一个python脚本中使用python函数的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58132861/

相关文章:

javascript - ES6 检测函数是否在类实例的原型(prototype)链上

python - 如何以编程方式确定函数/内置/可调用参数的数量?

c# - 如何在选择查询中添加函数

sql - postgresql 连接 2 个表和子查询,最后一个值 < 日期

python - 根据条件从 pandas 系列中删除重复项

python - 关于 python MRO 以及 super() 的行为

python - 返回 PIL 格式图像的简单绘图库?

python - 如何将提取的数据转换成python字典?

mysql - 3 个连接的 mysql 表的最新记录

SQL 查询计数