【问题标题】:Why does dir of a module show no __dict__? (python)为什么模块的目录没有显示 __dict__? (Python)
【发布时间】:2013-12-16 14:10:27
【问题描述】:

例如:

>>> import os
>>> '__dict__' in dir(os)
False

但是os.__dict__ 显示有一个__dict__ 属性。

【问题讨论】:

    标签: python dictionary module dir


    【解决方案1】:

    因为dir 对模块使用specialized implementation,它返回模块__dict__ 中的所有键,因此忽略了包含__dict__ 属性本身。

    看源码并不清楚这是否是故意的。

    【讨论】:

    • @RamchandraApte 我认为对你来说一切都是错误...... :)) 你一直在到处报告错误
    • @alKid 我在 Python 错误跟踪器上有点活跃,但不是很活跃,尤其是最近。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-27
    • 2011-06-20
    • 1970-01-01
    相关资源
    最近更新 更多