📌  相关文章
📜  如果对象具有属性 python 代码示例

📅  最后修改于: 2022-03-11 14:45:09.332000             🧑  作者: Mango

代码示例1
Use hasattr()

hasattr(object, name)
#The arguments are an object and a string.
#The result is True if the string is the name of one of the
#object’s attributes, False if not.
#(This is implemented by calling getattr(object, name) and
#seeing whether it raises an AttributeError or not.)

Docs: https://docs.python.org/3/library/functions.html#hasattr