LoginSignup
116
98

More than 3 years have passed since last update.

Python: オブジェクトのメソッド一覧を取得する

Last updated at Posted at 2016-07-12

Pythonでオブジェクトのメソッド名を全て取得する方法です。

print type(obj)
for x in inspect.getmembers(obj, inspect.ismethod):
  print x[0]
出力例
<class 'nfc.tag.tt3_sony.FelicaStandard'>
__init__
__str__
_format
_is_present
authenticate
dump
dump_service
format
polling
protect
read_from_ndef_service
read_without_encryption
request_response
request_service
request_system_code
search_service_code
send_cmd_recv_rsp
write_to_ndef_service
write_without_encryption

dirを使った方法もコメントにて紹介いただきました。

for x in dir(obj):
    print x, ':', type(eval("obj."+x))

最後までお読みくださりありがとうございました。Twitterでは、Qiitaに書かない技術ネタなどもツイートしているので、よかったらフォローお願いします:relieved:Twitter@suin

116
98
5

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
116
98