• hasattr(object, name)
  •    说明:判断对象object是否包含名为name的特性(hasattr是通过调用getattr(ojbect, name)是否抛出异常来实现的)。

       参数object:对象。

       参数name:特性名称。

       返回为True或者为False
  • 不过自己也可以定义一个方法
  •              def  getattribute(self, name):               
                    try:
                         r=object.__getattribute__(self, name)
                    except:
                         r=None 
                    return r

    通过返回值来判断!
  •   有hasattr就更方便了!

在自己的开发中遇见的问题,就是提取了没有的属性名称的处理方法!

 

相关文章:

  • 2021-09-26
  • 2021-11-14
  • 2021-07-15
  • 2022-12-23
  • 2022-02-02
  • 2022-02-26
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-01-27
  • 2021-05-18
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案