0

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 
5
  • 5
    __init__.py requires two underscores before and after init. You have only one on either side. Commented Mar 23, 2015 at 11:24
  • 3
    Python module names are case sensitive as well; your package is called info, all lower case, but your code imports Info, with a capital I. Commented Mar 23, 2015 at 11:25
  • i added the other underscores also but result is same Commented Mar 23, 2015 at 11:27
  • did u tried changing Info to info in your import Commented Mar 23, 2015 at 11:27
  • thanks Martijn Pieters Commented Mar 23, 2015 at 11:28

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.