To illustrate the issue I am having, please consider the following. I have two .py files, one named main.py
and the other named mymodule.py
. They are both in the same directory.
The contents of main.py
:
from mymodule import myfunction
myfunction()
The contents of mymodule.py
:
def myfunction():
for number in range(0,10):
print(number)
print("Hi")
I was under the impression that importing a function would only import that function. However, when I run main.py
, this is what I get:
Hi
0
1
2
3
4
5
6
7
8
9
Why is print("Hi")
being called? It isn't part of the function I imported!