Reputation: 11
I have created a package named math
. Inside this package I have created 2 files:
simple.py
__init__.py
And outside the package math
is my file main.py
.
__init__.py
looks like this:
a=1
This is the contents of main.py
:
import math
print(math.a)
The output should be 1
, but I am getting no output.
Even in case of
main.py
:
from math import simple
print(simple.add(1,2))
I am getting the error as: cannot import name simple
.
Can someone tell where I am going wrong?
Upvotes: 0
Views: 73
Reputation: 9891
There are three leads to this problem.
init.py
should be called __init__.py
,math
is also the name of a builtin package. Good chances are it is loaded instead of your package, and doesn't define a
,math
is defined is in your pythonpath (PYTHONPATH
environment variable).Upvotes: 1