python import module from a package

后端 未结 3 1046
执念已碎
执念已碎 2021-01-31 12:06

folder structure:


   main.py
   packages 
      __init__.py
      mod.py

main py:

3条回答
  •  一向
    一向 (楼主)
    2021-01-31 13:08

    See also: In Python, what exactly does “import *” import?

    adding __all__ to packages.__init__:

    __all__ = ['mod']
    from packages import *
    

    and module 'mod' will be imported, else 'mod' is not in the namespace of 'packages', but I can not explain why 'import *' without __all__ do not import 'mod'.

提交回复
热议问题