Is it good practice to use `import __main__`?

后端 未结 2 540
-上瘾入骨i
-上瘾入骨i 2020-12-01 07:40

I\'m working on a relatively large Python application, and there are several resources that I would like to keep as global variables accessible throughout several different

2条回答
  •  悲&欢浪女
    2020-12-01 08:25

    Doing so requires violating PEP8, which specifies

    Imports are always put at the top of the file, just after any module comments and docstrings, and before module globals and constants.

    In order for gui.py to successfully import __main__.DEBUG, you would have to set the value of DEBUG before import gui.

提交回复
热议问题