このことを考慮:
>>> import math
>>> dir(math)
['__doc__', '__name__', '__package__', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'ceil', 'copysign', 'cos', 'cosh', 'degrees', 'e', 'exp', 'fabs', 'factorial', 'floor', 'fmod', 'frexp', 'fsum', 'hypot', 'isinf', 'isnan', 'ldexp', 'log', 'log10', 'log1p', 'modf', 'pi', 'pow', 'radians', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'trunc']
__dict__
リストされていませんが、私はまだすることができます
>>> math.__dict__
と同じこと
>>> class MyClass(object):
def __init__(self, var1, var2):
self.a = var1
self.b = var2
def __call__(self, arg):
print " The arg passed is ", arg
>>> dir(MyClass)
['__call__', '__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__']
__bases__
リストされて__base__
いませんが、私はまだ行うことができます:
>>> MyClass.__bases__
(<type 'object'>,)
>>> MyClass.__base__
<type 'object'>
質問:
Pythonオブジェクトから到達可能なすべての属性を事前に知るまたは伝えるにはどうすればよいですか?この場合、math
モジュールが持っていること__dict__
とMyClass
持っていること、__base__
そして持っていることをどのように知ることができ__bases__
ますか?