Reputation: 67
I have two modules in the same directory, one has the function in it. I am trying to call the function into my another module, but I am facing AttributeError
module1:
from tank import cal as c
def water():
lev1=c.rec1
lev2=c.rec2
lev3=c.rec3
print(lev1)
print(lev2)
print(lev3)
module2:
from tank import level as lv
a=input("enter the number")
rec1=a[1:5]
rec2=a[5:9]
rec3=a[9:13]
lv.water()
Error:
AttributeError: module 'tank.level' has no attribute 'water'
Directory Structure:
Data
--tank
--__init__.py
--cal.py
--level.py
Upvotes: 0
Views: 681
Reputation: 2414
You have two modules that are importing each other! You shouldn't have cyclical imports like this; one way to fix this is to have the water() function accept some arguments instead of directly trying to import values from the other module.
def water(lev1, lev2, lev3):
print(lev1)
print(lev2)
print(lev3)
Upvotes: 1