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

这段意思没看懂,求助

  •  
  •   pla · Oct 7, 2017 · 2354 views
    This topic created in 3170 days ago, the information mentioned may be changed or developed.

    stackoverflow 上关于 What will happen if two modules import each other? 的讨论

    https://stackoverflow.com/questions/744373/circular-or-cyclic-imports-in-python

    这一段没看懂,哪个是哪个看晕了:

    Finally, the executing script runs in a module named __main__, importing the script under its own name will create a new module unrelated to __main__.


    例子

    # first.py
    from second import b
    
    def a():
        print('This is a')
    
    
    # second.py
    from first import a
    
    def b():
        print('This is b')
    
    
    

    执行 second.py

    1 replies    2017-10-07 20:42:28 +08:00
    geelaw
        1
    geelaw  
       Oct 7, 2017   ❤️ 2
    python some_file.py 的时候,some_file.py 就是 the executing script。

    意思是 some_file.py 自己也成为 module,并且这个 module 的名字叫 __main__,如果 some_file.py 直接或者间接地导入 some_file.py 自己,则被导入的 some_file.py 会成为一个新的 module,且这个新的 module 不是原来的 __main__。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3193 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 03:53 · PVG 11:53 · LAX 20:53 · JFK 23:53
    ♥ Do have faith in what you're doing.