推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
twitterpig
V2EX  ›  Python

关于 dir 函数的一个小疑问。

  •  
  •   twitterpig · Jun 3, 2017 · 3264 views
    This topic created in 3411 days ago, the information mentioned may be changed or developed.
    >随后,我们以不传递参数的形式使用 dir 函数。在默认情况下,它将返回当前模块的属性列表。要注意到被导入进来的模块所能生成的列表也会是这一列表的一部分。

    #给出当前模块的属性名称

    dir()
    ['__builtins__', '__doc__', '__name__', '__package__']
    这个“返回当名模块”的到底是哪个模块? 模块名是什么?

    比如下面这个例子:
    import sys
    #给出 sys 模块中的属性名称
    dir(sys)
    ['__displayhook__', '__doc__', 'argv', 'builtin_module_names', 'version', 'version_info']
    #only few entries shown here
    这个例子中很明显导入的是 sys 模块。

    求指教。

    Byte Of Python 73P
    ruoyu0088
        1
    ruoyu0088  
       Jun 3, 2017   ❤️ 1
    Python 中每个文件就是一个模块,dir()得到当前文件中的所有全局名字。当前模块名就是当前文件的名字。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2356 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 11:13 · PVG 19:13 · LAX 04:13 · JFK 07:13
    ♥ Do have faith in what you're doing.