想不想知道import的包裏,全局都有啥?
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
from collections import Iterable
import numpy as np
import types
import sklearn
import sklearn.cluster
print(type(sklearn.cluster.AffinityPropagation))
# return(list(filter(lambda m: not m.startswith("__") and not m.endswith("__") and callable(getattr(self, m)), dir(self))))
def F(clsname, space):
if '__' in clsname:
return
try:
__import__(clsname)
print('\033[31m' + space + clsname + "模塊\033[0m")
except:
return
m = sys.modules[clsname]
for func in dir(m):
if not (func.endswith("_") or func.startswith("_")):
if func.islower():
print(space + space + " ." + func + "()")
else:
print(space + space + " ." + func )
attstrlist = dir(m)
for attstr in attstrlist:
submodules = getattr(m, attstr)
# if isinstance(submodules, types.ModuleType):
# print(space + " " + submodules.__name__ + "模塊")
if isinstance(submodules, type):
print(space + " \033[0;34m" + clsname + "." + submodules.__name__ + "類\033[0m")
for func in dir(submodules):
if not (func.endswith("_") or func.startswith("_")):
print(space + space + " ." + func + "()")
if isinstance(submodules, Iterable):
try:
for sm in submodules:
if isinstance(sm, str) and len(sm) > 1:
F(clsname + '.' + sm, " " + space)
except:
pass
# F("sklearn", "")
# F("numpy", "")
F("pandas", "")
大概長這樣的,如果誰有興趣,幫我完善一下。
python3 的反射不大好用,有些類型type沒搞清楚。
目前能大概羅列出一個骨架