Multilevel relative import

后端 未结 2 652
执念已碎
执念已碎 2020-12-31 03:15

Multilevel relative import

I have following folder structure

top\\
   __init__.py
   util\\
      __init__.py
      utiltest.py
   foo\\
      __init         


        
2条回答
  •  青春惊慌失措
    2020-12-31 03:35

    You must import foobar from the parent folder of top:

    import top.foo.bar.foobar
    

    This tells Python that top is the top level package. Relative imports are possible only inside a package.

提交回复
热议问题