I am new to Python. I was playing with "Importing modules" in python and came to this 'thing' :
This is my main.py
import test
test.hello()
This is my test.py
import main
def hello():
print("hello")
It results in
Traceback (most recent call last):
File "main.py", line 1, in <module>
import test
File "/home/imtiazirtiaz/Desktop/Python/test/test.py", line 1, in <module>
import main
File "/home/imtiazirtiaz/Desktop/Python/test/main.py", line 3, in <module>
test.hello()
AttributeError: module 'test' has no attribute 'hello'
So I thought the function was not defined. So I changed the test.py
def hello():
print("hello")
import main
But now when I run main.py
, the output is:
hello
hello
Why does it prints hello
twice?
And running the test.py
says:
hello
Please help me showing what is going on. How does cross importing modules work in python?
I am using python 3.6