hasattr具有功能

I15*_*159 1 python attributes hasattr

如何用hasattr(或不用)检查函数或方法中的attr存在?当我尝试以任何方式检查它是否为假:

>>> def f():
        at = True


>>> hasattr(f, 'at')
False
>>> hasattr(f(), 'at')
False
Run Code Online (Sandbox Code Playgroud)

Ign*_*ams 5

局部变量不是属性.你不能使用任何*attr()来欺骗他们.