Python: modules and packaging - why isn't __init__.py file executed before __main__.py?

后端 未结 3 1684
暖寄归人
暖寄归人 2021-01-04 07:56

I have a python program that is entirely contained in a directory with the following structure:

myprog/
├── __init__.py
├── __main__.py
├── moduleone.py
└──          


        
3条回答
  •  没有蜡笔的小新
    2021-01-04 08:21

    So, having looked at the other responses and not being thrilled, I tried:

    from __init__ import *
    

    from my __main__.py file.

    I suppose it doesn't allow you to refer to the module by name, but for simple cases it seems to work.

提交回复
热议问题