に表示する属性を次のpythonの例を考えてみてくださいガイド:はすべて、Pythonの `__dict__`方法
In [3]: class test(object):
...: attribute='3'
...: def __init__(self):
...: self.other='4'
...:
In [4]: b=test()
In [5]: b.attribute
Out[5]: '3'
In [6]: b.__dict__
Out[6]: {'other': '4'}
なぜそれが__dict__
だけ"other"
属性ではなく"atribute"
を示したということでしょうか?
そして、すべてのクラスとその属性と値を持つ辞書を取得するにはどうすればよいですか?つまり、私はこれをどうやって得るのですか?
{'other': '4', 'attribute': '3'}
そして、__dict__
などの簡単な手段を使用しています。
PS:this questionに関連していますが、そこからはっきりとdictを得ることはできませんでした。
PS2:私は
In [3]: class test(object):
...: attribute='3'
...: def __init__(self):
...: self.other='4'
...: def _print_atr(self):
...: # This should print exactly {'other': '4', 'attribute': '3'}
...: print(self.__all_atr__)
In [4]: b=test()
In [5]: b.attribute
Out[5]: '3'
In [6]: b.__dict__
Out[6]: {'other': '4'}
乾杯
あなたはPS2の意味を詳しく説明できますか?なぜあなたの仮説 '__all_atr__'は' __init__'と '_print_atr'を除いていますか?_does_は' attribute'を含んでいますか? – mgilson
@mgilsonはい、申し訳ありませんが、それがはっきりしていない場合、それはまさにそれがやることです。私の例外の例を出力します: '{'other': '4'、 'attribute': '3'}'。 – TomCho
しかし_why_?いくつかのものを排除するためのルールとは何かを排除するルールは何ですか? – mgilson