Suppose I have a module package containing the following files. An empty file C:\codes\package\__init__.py
and some non-trivial files:
One located in C:\codes\package\first.py
def f():
print 'a'
Another located in C:\codes\package\second.py
def f():
print 'b'
There is also a third file: C:\codes\package\general.py
with the following code
def myPrint(module_name):
module = __import__(module_name)
module.f()
if __name__ == '__main__':
myPrint('first')
myPrint('second')
When I run the latter file, everything goes fine. However, if I try to execute the file C:\codes\test.py
containing
if __name__ == '__main__':
from package import general
general.myPrint('first')
general.myPrint('second')
I get the import error ImportError: No module named first
. How to resolve this issue?