help(dir):
dir([object]) -> list of strings If called without an argument, return the names in the current scope. Else, return an alphabetized list of names comprising (some of) the attributes of the given object, and of attributes reachable from it. If the object supplies a method named __dir__, it will be used; otherwise the default dir() logic is used and returns: for a module object: the module's attributes. for a class object: its attributes, and recursively the attributes of its bases. for any other object: its attributes, its class's attributes, and recursively the attributes of its class's base classes.
dir組み込み関数のヘルプファイルに問題がある可能性があります。例:
class AddrBookEntry(object):
'address book entry class'
def __init__(self,nm,ph):
self.name=nm
self.phone=ph
def updatePhone(self,newph):
self.phone=newph
print 'Updated phone # for :' ,self.name
dir(AddrBookEntry('tom','123'))
['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'name', 'phone', 'updatePhone']
1.dir()
オブジェクトのメソッドを一覧表示できます。属性だけでなく
、updatePhone
isメソッドであり、属性ではありません。
2.dir()の出力のメソッドである属性を知るにはどうすればよいですか?