Reputation: 53
I am beginner in python
i have following directory structure
python_programs/
addition.py
info/_init_.py
msg1.py
msg2.py
msg3.py
In addition.py i have the following code:-
import Info
Info.msg1()
Info.msg2()
Info.msg3()
In init.py i have the following code
from msg1 import msg1
from msg2 import msg2
from msg3 import msg3
In msg1.py i have the following code:-
def msg1():
print "This is msg1"
In msg2.py i have the following code:-
def msg2():
print "This is msg2"
In msg3.py i have the following code:-
def msg3():
print "This is msg3"
but when i tried to run the addition.py file
it is giving me error:-
Traceback (most recent call last):
File "addition.py", line 2, in <module>
import Info
ImportError: No module named Info
Upvotes: 0
Views: 2462
Reputation: 1124718
You have made two mistakes:
To create a package, the file must be named __init__.py
(double underscores on either side), not _init_.py
.
Python is case sensitive. You named your package info
(lowercase), but try to import Info
(uppercase I
); these don't match. Rename one or the other to match case correctly.
Upvotes: 3