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

前端 未结 4 615
情话喂你
情话喂你 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:15

    From Python: import the containing package:

    Importing __init__ seems to work fine.

    import __init__
    
    class Good(object):
        def __init__(self):
            print hello1.A
    

提交回复
热议问题