I have a file called test1.py with the following code:
print("HELLO WORLD")
x=999
I have another file called test2.py with the following code:
from test1 import x
print(x,"hello!")
Why is this the output:
HELLO WORLD
999 hello!
Why does it perform the function in test1 instead of just getting me the variable x
?
In test.py I have tried:
from test1 import x as a
print(a,"hello!")
This gets me the same output.
Expected result:
999 hello!
Actual result:
HELLO WORLD
999 hello!
Sorry if this was a repeated question - I just can't find a solution.
EDIT: This was marked as a duplicate earlier - one problem with that: using if __name__ == "__main__"
logic prevents me from accessing any variable in main. I just want a variable without running the file.