different import results at different directories

前端 未结 1 960
鱼传尺愫
鱼传尺愫 2021-01-06 10:08

I have a package MyPak and a module MyMod. The files are organized in the following way:

somedir/MyPak/MyMod.py

in MyMod.py ther

相关标签:
1条回答
  • 2021-01-06 10:49

    This behavior is indicative that you have a file:

    somedir/MyPak/__init__.py
    

    wherein you do the following:

    from MyMod import *
    

    When you import MyPak, it imports from that __init__.py - likewise, when you from MyPak import something, it's going to try to pull from the namespace for the package - which will look inside that __init__.py

    Because you imported everything from MyMod inside __init__.py, now the class is local to the MyPak package, and masks the MyMod.py file.

    0 讨论(0)
提交回复
热议问题