Is it possible to access the variables in __init__.py from the modules in the same package?

前端 未结 4 608
情话喂你
情话喂你 2021-02-07 01:41

I have a hello1 package that contains good.py module.

hello1
├── __init__.py
└── good.py

The init module has a variable

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-07 02:05

    You have to explicit import the constants you want to use.

    It's preferable to have all your constants in a "config" file (i.e. config.py) ) and then if you want them in the package namespace, import them.

    init.py file:

    from package.config import *
    

    it's more clear that way

提交回复
热议问题