Python打印类的所有属性

解决方案

def print_object(obj):
    print('\n'.join(['%s:%s' % item for item in obj.__dict__.items()]))

实例

import numpy

def print_object(obj):
    print('\n'.join(['%s:%s' % item for item in obj.__dict__.items()]))

print_object(numpy.ndarray)

效果

__repr__:<slot wrapper '__repr__' of 'numpy.ndarray' objects>
__hash__:None
__str__:<slot wrapper '__str__' of 'numpy.ndarray' objects>
__lt__:<slot wrapper '__lt__' of 'numpy.ndarray' objects>
__le__:<slot wrapper '__le__' of 'numpy.ndarray' objects>
__eq__:<slot wrapper '__eq__' of 'numpy.ndarray' objects>
__ne__:<slot wrapper '__ne__' of 'numpy.ndarray' objects>
__gt__:<slot wrapper '__gt__' of 'numpy.ndarray' objects>
__ge__:<slot wrapper '__ge__' of 'numpy.ndarray' objects>
__iter__:<slot wrapper '__iter__' of 'numpy.ndarray' objects>
__add__:<slot wrapper '__add__' of 'numpy.ndarray' objects>
__radd__:<slot wrapper '__radd__' of 'numpy.ndarray' objects>
__sub__:<slot wrapper '__sub__' of 'numpy.ndarray' objects>
__rsub__:<slot wrapper '__rsub__' of 'numpy.ndarray' objects>
__mul__:<slot wrapper '__mul__' of 'numpy.ndarray' objects>
__rmul__:<slot wrapper '__rmul__' of 'numpy.ndarray' objects>
__mod__:<slot wrapper '__mod__' of 'numpy.ndarray' objects>
__rmod__:<slot wrapper '__rmod__' of 'numpy.ndarray' objects>
__divmod__:<slot wrapper '__divmod__' of 'numpy.ndarray' objects>
__rdivmod__:<slot wrapper '__rdivmod__' of 'numpy.ndarray' objects>
__pow__:<slot wrapper '__pow__' of 'numpy.ndarray' objects>
__rpow__:<slot wrapper '__rpow__' of 'numpy.ndarray' objects>
__neg__:<slot wrapper '__neg__' of 'numpy.ndarray' objects>
__pos__:<slot wrapper '__pos__' of 'numpy.ndarray' objects>
__abs__:<slot wrapper '__abs__' of 'numpy.ndarray' objects>
__bool__:<slot wrapper '__bool__' of 'numpy.ndarray' objects>
__invert__:<slot wrapper '__invert__' of 'numpy.ndarray' objects>
__lshift__:<slot wrapper '__lshift__' of 'numpy.ndarray' objects>
__rlshift__:<slot wrapper '__rlshift__' of 'numpy.ndarray' objects>
__rshift__:<slot wrapper '__rshift__' of 'numpy.ndarray' objects>
__rrshift__:<slot wrapper '__rrshift__' of 'numpy.ndarray' objects>
__and__:<slot wrapper '__and__' of 'numpy.ndarray' objects>
__rand__:<slot wrapper '__rand__' of 'numpy.ndarray' objects>
__xor__:<slot wrapper '__xor__' of 'numpy.ndarray' objects>
__rxor__:<slot wrapper '__rxor__' of 'numpy.ndarray' objects>
__or__:<slot wrapper '__or__' of 'numpy.ndarray' objects>
__ror__:<slot wrapper '__ror__' of 'numpy.ndarray' objects>
__int__:<slot wrapper '__int__' of 'numpy.ndarray' objects>
__float__:<slot wrapper '__float__' of 'numpy.ndarray' objects>
__iadd__:<slot wrapper '__iadd__' of 'numpy.ndarray' objects>
__isub__:<slot wrapper '__isub__' of 'numpy.ndarray' objects>
__imul__:<slot wrapper '__imul__' of 'numpy.ndarray' objects>
__imod__:<slot wrapper '__imod__' of 'numpy.ndarray' objects>
__ipow__:<slot wrapper '__ipow__' of 'numpy.ndarray' objects>
__ilshift__:<slot wrapper '__ilshift__' of 'numpy.ndarray' objects>
__irshift__:<slot wrapper '__irshift__' of 'numpy.ndarray' objects>
__iand__:<slot wrapper '__iand__' of 'numpy.ndarray' objects>
__ixor__:<slot wrapper '__ixor__' of 'numpy.ndarray' objects>
__ior__:<slot wrapper '__ior__' of 'numpy.ndarray' objects>
__floordiv__:<slot wrapper '__floordiv__' of 'numpy.ndarray' objects>
__rfloordiv__:<slot wrapper '__rfloordiv__' of 'numpy.ndarray' objects>
__truediv__:<slot wrapper '__truediv__' of 'numpy.ndarray' objects>
__rtruediv__:<slot wrapper '__rtruediv__' of 'numpy.ndarray' objects>
__ifloordiv__:<slot wrapper '__ifloordiv__' of 'numpy.ndarray' objects>
__itruediv__:<slot wrapper '__itruediv__' of 'numpy.ndarray' objects>
__index__:<slot wrapper '__index__' of 'numpy.ndarray' objects>
__matmul__:<slot wrapper '__matmul__' of 'numpy.ndarray' objects>
__rmatmul__:<slot wrapper '__rmatmul__' of 'numpy.ndarray' objects>
__imatmul__:<slot wrapper '__imatmul__' of 'numpy.ndarray' objects>
__len__:<slot wrapper '__len__' of 'numpy.ndarray' objects>
__getitem__:<slot wrapper '__getitem__' of 'numpy.ndarray' objects>
__setitem__:<slot wrapper '__setitem__' of 'numpy.ndarray' objects>
__delitem__:<slot wrapper '__delitem__' of 'numpy.ndarray' objects>
__contains__:<slot wrapper '__contains__' of 'numpy.ndarray' objects>
__new__:<built-in method __new__ of type object at 0x000007FED6283E00>
__array__:<method '__array__' of 'numpy.ndarray' objects>
__array_prepare__:<method '__array_prepare__' of 'numpy.ndarray' objects>
__array_wrap__:<method '__array_wrap__' of 'numpy.ndarray' objects>
__array_ufunc__:<method '__array_ufunc__' of 'numpy.ndarray' objects>
__array_function__:<method '__array_function__' of 'numpy.ndarray' objects>
__sizeof__:<method '__sizeof__' of 'numpy.ndarray' objects>
__copy__:<method '__copy__' of 'numpy.ndarray' objects>
__deepcopy__:<method '__deepcopy__' of 'numpy.ndarray' objects>
__reduce__:<method '__reduce__' of 'numpy.ndarray' objects>
__reduce_ex__:<method '__reduce_ex__' of 'numpy.ndarray' objects>
__setstate__:<method '__setstate__' of 'numpy.ndarray' objects>
dumps:<method 'dumps' of 'numpy.ndarray' objects>
dump:<method 'dump' of 'numpy.ndarray' objects>
__complex__:<method '__complex__' of 'numpy.ndarray' objects>
__format__:<method '__format__' of 'numpy.ndarray' objects>
all:<method 'all' of 'numpy.ndarray' objects>
any:<method 'any' of 'numpy.ndarray' objects>
argmax:<method 'argmax' of 'numpy.ndarray' objects>
argmin:<method 'argmin' of 'numpy.ndarray' objects>
argpartition:<method 'argpartition' of 'numpy.ndarray' objects>
argsort:<method 'argsort' of 'numpy.ndarray' objects>
astype:<method 'astype' of 'numpy.ndarray' objects>
byteswap:<method 'byteswap' of 'numpy.ndarray' objects>
choose:<method 'choose' of 'numpy.ndarray' objects>
clip:<method 'clip' of 'numpy.ndarray' objects>
compress:<method 'compress' of 'numpy.ndarray' objects>
conj:<method 'conj' of 'numpy.ndarray' objects>
conjugate:<method 'conjugate' of 'numpy.ndarray' objects>
copy:<method 'copy' of 'numpy.ndarray' objects>
cumprod:<method 'cumprod' of 'numpy.ndarray' objects>
cumsum:<method 'cumsum' of 'numpy.ndarray' objects>
diagonal:<method 'diagonal' of 'numpy.ndarray' objects>
dot:<method 'dot' of 'numpy.ndarray' objects>
fill:<method 'fill' of 'numpy.ndarray' objects>
flatten:<method 'flatten' of 'numpy.ndarray' objects>
getfield:<method 'getfield' of 'numpy.ndarray' objects>
item:<method 'item' of 'numpy.ndarray' objects>
itemset:<method 'itemset' of 'numpy.ndarray' objects>
max:<method 'max' of 'numpy.ndarray' objects>
mean:<method 'mean' of 'numpy.ndarray' objects>
min:<method 'min' of 'numpy.ndarray' objects>
newbyteorder:<method 'newbyteorder' of 'numpy.ndarray' objects>
nonzero:<method 'nonzero' of 'numpy.ndarray' objects>
partition:<method 'partition' of 'numpy.ndarray' objects>
prod:<method 'prod' of 'numpy.ndarray' objects>
ptp:<method 'ptp' of 'numpy.ndarray' objects>
put:<method 'put' of 'numpy.ndarray' objects>
ravel:<method 'ravel' of 'numpy.ndarray' objects>
repeat:<method 'repeat' of 'numpy.ndarray' objects>
reshape:<method 'reshape' of 'numpy.ndarray' objects>
resize:<method 'resize' of 'numpy.ndarray' objects>
round:<method 'round' of 'numpy.ndarray' objects>
searchsorted:<method 'searchsorted' of 'numpy.ndarray' objects>
setfield:<method 'setfield' of 'numpy.ndarray' objects>
setflags:<method 'setflags' of 'numpy.ndarray' objects>
sort:<method 'sort' of 'numpy.ndarray' objects>
squeeze:<method 'squeeze' of 'numpy.ndarray' objects>
std:<method 'std' of 'numpy.ndarray' objects>
sum:<method 'sum' of 'numpy.ndarray' objects>
swapaxes:<method 'swapaxes' of 'numpy.ndarray' objects>
take:<method 'take' of 'numpy.ndarray' objects>
tobytes:<method 'tobytes' of 'numpy.ndarray' objects>
tofile:<method 'tofile' of 'numpy.ndarray' objects>
tolist:<method 'tolist' of 'numpy.ndarray' objects>
tostring:<method 'tostring' of 'numpy.ndarray' objects>
trace:<method 'trace' of 'numpy.ndarray' objects>
transpose:<method 'transpose' of 'numpy.ndarray' objects>
var:<method 'var' of 'numpy.ndarray' objects>
view:<method 'view' of 'numpy.ndarray' objects>
ndim:<attribute 'ndim' of 'numpy.ndarray' objects>
flags:<attribute 'flags' of 'numpy.ndarray' objects>
shape:<attribute 'shape' of 'numpy.ndarray' objects>
strides:<attribute 'strides' of 'numpy.ndarray' objects>
data:<attribute 'data' of 'numpy.ndarray' objects>
itemsize:<attribute 'itemsize' of 'numpy.ndarray' objects>
size:<attribute 'size' of 'numpy.ndarray' objects>
nbytes:<attribute 'nbytes' of 'numpy.ndarray' objects>
base:<attribute 'base' of 'numpy.ndarray' objects>
dtype:<attribute 'dtype' of 'numpy.ndarray' objects>
real:<attribute 'real' of 'numpy.ndarray' objects>
imag:<attribute 'imag' of 'numpy.ndarray' objects>
flat:<attribute 'flat' of 'numpy.ndarray' objects>
ctypes:<attribute 'ctypes' of 'numpy.ndarray' objects>
T:<attribute 'T' of 'numpy.ndarray' objects>
__array_interface__:<attribute '__array_interface__' of 'numpy.ndarray' objects>
__array_struct__:<attribute '__array_struct__' of 'numpy.ndarray' objects>
__array_priority__:<attribute '__array_priority__' of 'numpy.ndarray' objects>
__array_finalize__:<attribute '__array_finalize__' of 'numpy.ndarray' objects>
__doc__:None

参考文献

  1. python打印一个对象所有属性的方法
发布了223 篇原创文章 · 获赞 63 · 访问量 12万+

猜你喜欢

转载自blog.csdn.net/lly1122334/article/details/103920351
今日推荐