python 中查看 对象的包含的属性和方法

通过 dir 方法 可以查看

dir(obj)

如果是自定义类生成的对象,可以通过 __dict__ 属性来查看,

class Test():
''' this is document ''' x
=1 def __init__(self,name,age): self.name=name self.age=age a=Test('serendipity',21) a.__dict__ #{'age': 23, 'name': 'serendipity'} Test.__dict__ # {'x': 1, '__module__': '__main__', '__doc__': ' this is document ', '__init__': <function __init__ at 0xb6c69030>}

 

posted @ 2022-07-13 10:44  Orientation  阅读(263)  评论(0编辑  收藏  举报