Python 在一个对象中打印所有属性的类型-最佳方式?

Python 在一个对象中打印所有属性的类型-最佳方式?,python,object,types,attributes,Python,Object,Types,Attributes,我找到了答案,但我认为应该有一个更简单的方法 下面是我的示例:从对象boston,我想知道attibutes是字符串还是数组。 a) 告诉我名字。 b) 给我的显然不是我想要的信息 c) 给我想要的 但我认为选项c)过于复杂,应该有更干净的方法来做到这一点。有什么想法吗 从sklearn.datasets导入* 波士顿=加载波士顿() a=dir(波士顿) b=[在波士顿为x键入(x)] c=[type(getattr(boston,name))。_name__表示目录中的名称(boston)]

我找到了答案,但我认为应该有一个更简单的方法

下面是我的示例:从对象boston,我想知道attibutes是字符串还是数组。 a) 告诉我名字。 b) 给我的显然不是我想要的信息 c) 给我想要的 但我认为选项c)过于复杂,应该有更干净的方法来做到这一点。有什么想法吗

从sklearn.datasets导入*
波士顿=加载波士顿()
a=dir(波士顿)
b=[在波士顿为x键入(x)]
c=[type(getattr(boston,name))。_name__表示目录中的名称(boston)]
打印(a,“\n”,b,“\n”,c)
输出:

['DESCR','data','feature_name','filename','target']
[, , ] 
['str','ndarray','ndarray','str','ndarray']
输出:

['data','target','feature_name','DESCR','filename']
[, , ]

非常感谢!这正是我想要的。
['DESCR', 'data', 'feature_names', 'filename', 'target'] 
[<class 'str'>, <class 'str'>, <class 'str'>, <class 'str'>, <class 'str'>] 
['str', 'ndarray', 'ndarray', 'str', 'ndarray']
print([x for x in boston])
print([type(boston[x]) for x in boston])
['data', 'target', 'feature_names', 'DESCR', 'filename']
[<class 'numpy.ndarray'>, <class 'numpy.ndarray'>, <class 'numpy.ndarray'>, <class 'str'>, <class 'str'>]