LoginSignup
0
0

More than 1 year has passed since last update.

Pythonでライブラリの調査をする際のメモ

Last updated at Posted at 2022-09-19

dirとinspect.getsourceがいい感じ

未知のライブラリとか、普段使ってるライブラリだけど他にどんなメソッドがあるんだろ?って時にオススメ。

import importlib
import inspect
from pprint import pprint

library_name = input('調査対象のライブラリ名を入れてちょ :')

m = importlib.import_module(library_name)

print('-----<dir>-----')
for c,a in enumerate(dir(m)):
    print(f"{c:4}, {a:20}, {type(eval('m.' + a))}")

print()    
print(f"-----<inspect.getsorce [{ library_name }] >-----")
print(inspect.getsource(m))

出力結果

※inputに「pprint」を入れた場合(出力結果長いので途切れてるけど、ソースが長々と表示されてます)

image.png

0
0
0

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
0
0