推荐学习书目
› 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

Byte of Python 模块部分代码示例解答内容疑问?

  •  
  •   twitterpig · May 21, 2017 · 2259 views
    This topic created in 3420 days ago, the information mentioned may be changed or developed.

    输入: https://gist.github.com/MaverickChan/0c7b01a9cdd50c03107e180ba7696a7d

    输出: The command line arguments are:

    module_using_sys.py

    we

    are

    arguments

    The PYTHONPATH is ['/Users/XXX/Desktop/Python', '/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python36.zip', '/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6', '/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/lib-dynload', '/usr/local/lib/python3.6/site-packages']

    书中的解释:

    sys.path 内包含了导入模块的字典名称列表。你能观察到 sys.path 的第一段字符串是空的——这一空字符串代表当前目录也是 sys.path 的一部分,它与 PYTHONPATH 环境变量等同。这意味着你可以直接导入位于当前目录的模块。否则,你必须将你的模块放置在 sys.path 内所列出的目录中。

    疑问:

    1.你能观察到 sys.path 的第一段字符串是空的——

    ------但是我找了半天也没看到这个描述的空格——

    2.这一空字符串代表当前目录也是 sys.path 的一部分,它与 PYTHONPATH 环境变量等同。这意味着你可以直接导入位于当前目录的模块。否则,你必须将你的模块放置在 sys.path 内所列出的目录中。

    ------直接可以导入当前目录的模块的条件如何判断?其实我还是不太明白这句话。

    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2302 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 22ms · UTC 05:43 · PVG 13:43 · LAX 22:43 · JFK 01:43
    ♥ Do have faith in what you're doing.