V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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 · 2017-06-03 19:23:54 +08:00 · 2065 次点击
    这是一个创建于 2489 天前的主题,其中的信息可能已经有所发展或是发生改变。
    >随后,我们以不传递参数的形式使用 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  
       2017-06-03 21:17:09 +08:00   ❤️ 1
    Python 中每个文件就是一个模块,dir()得到当前文件中的所有全局名字。当前模块名就是当前文件的名字。
    troywinter
        2
    troywinter  
       2017-06-04 11:46:21 +08:00   ❤️ 1
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5490 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 08:24 · PVG 16:24 · LAX 01:24 · JFK 04:24
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.