I am trying to import variables from another module. My wish is to use the "import module" way not the "from x import y" way. The import line works, but I get an error when trying to print variables from the source module.
I have an empty init.py file; All files init, module1 and module2 are in the same folder. The folder is seen in sys.path. Using from x import y works. I wanna use just import module. What am I missing?
module1.py:
X=8 List=[8,2,9] ListOfStrings=["Champa","Lampa", "Dampa"] All=[X, List, ListOfStrings, String] print(All)\ module2.py:
import module1 import sys for p in sys.path: print(p) print(X) module1 is run but X shows as not defined.
Result:
[8, [8, 2, 9], ['Champa', 'Lampa', 'Dampa'], 'This is a string'] theactualpath\Desktop\Work Excercises\py_test Traceback (most recent call last): File "theactualpath\Desktop\Work Excercises\py_test\module2.py", line 6, in <module> print(X) NameError: name 'X' is not defined [Finished in 0.1s with exit code 1] [shell_cmd: python -u "theactualpath\Desktop\Work\Excercises\py_test\module2.py"] [dir: theactualpath\Desktop\Work Excercises\py_test] [path: various paths from my computer, not the current working folder thou]
module1