python-3.x - 从被调用函数访问类属性?
问题描述
假设我有这样的事情:
--module1
def called():
if caller.class.attrX == 1 : ...
--module2
class ABC:
attrX = 1
def method():
called()
我想访问调用者 Class-attribute 吗?
我知道我必须以某种方式使用检查,但可以弄清楚到底如何。蟒蛇3
解决方案
将变量传递给函数是最好的(也是唯一的?)选项。
--module1
def called(attrX):
if attrX == 1 : ...
--module2
class ABC:
self.attrX = 1
def method():
called(self.attrX)
推荐阅读
- lua - Players.Jackwithgamingyt.Playergui.ScreenGui.LocalScript:93 尝试使用“名称”进行索引
- c++ - 为什么编译器说这个宏函数需要右括号?
- cmake - “cmake_minimum_required(VERSION 3.10)”中的“VERSION”是什么
- excel - 多个索引匹配公式会降低 Excel 工作表的性能
- blockchain - 处理事务时出现 VM 异常:还原
- reactjs - 为什么 useState 会在点击时随机更改我的图像?
- php - 当我运行`php artisan storage:link`时,Laravel 8.60.0 创建一个文件而不是文件夹/符号链接
- list - 具有空列表值的字典
- flutter - 如何在一定时间内使用 await 运行函数
- input - 如何处理从右到左的一行输入?