Skip to content Skip to sidebar Skip to footer

Different Import Results At Different Directories

I have a package MyPak and a module MyMod. The files are organized in the following way: somedir/MyPak/MyMod.py in MyMod.py there is only a Class whose name is also MyMod in dire

Solution 1:

This behavior is indicative that you have a file:

somedir/MyPak/__init__.py

wherein you do the following:

fromMyModimport *

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.

Post a Comment for "Different Import Results At Different Directories"