python所有模块列表_如何获取Python当前模块中所有类的列表?

我能够从dir内置plus中获得所需的一切getattr。

# Works on pretty much everything, but be mindful that

# you get lists of strings back

print dir(myproject)

print dir(myproject.mymodule)

print dir(myproject.mymodule.myfile)

print dir(myproject.mymodule.myfile.myclass)

# But, the string names can be resolved with getattr, (as seen below)

不过,它的确看起来像个毛线球:

def list_supported_platforms():

"""

List supported platforms (to match sys.platform)

@Retirms:

list str: platform names

"""

return list(itertools.chain(

*list(

# Get the class's constant

getattr(

# Get the module's first class, which we wrote

getattr(

# Get the module

getattr(platforms, item),

dir(

getattr(platforms, item)

)[0]

),

'SYS_PLATFORMS'

)

# For each include in platforms/__init__.py

for item in dir(platforms)

# Ignore magic, ourselves (index.py) and a base class.

if not item.startswith('__') and item not in ['index', 'base']

)

))

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值