Consider an example,
I have a package having list of modules:
# only mod2 should import
# only mod1,mod3 should import
I don't think that packages should control who and how can import them, basically packages should not know about their importers. However if you for some reason still thing this is a good idea, you can get a main filename by:
import __main__ main_file = __main__.__file__
And then modify your
attribute of module based on a main file name.