# file1.py
a = 1
print(a)
# 1
# file2.py
from file1 import a
print(a)
# 0
I want "1" output in file2.py, why it doesn't work?
Your code should give the below output
1
1
You get two 1's in the output because when python imports a file it executes it. When file1 is imported, it's print statement is executed. The second 1 is from the print statement in the file2
If you are getting 0 as output check if you have the permissions to execute these files (Since your files are in root directory)
ModuleNotFoundError: No module named 'file1'#0he meant the output was0