I want to use a variable that I assigned in another file, is there a way that the import of that variable from that file will maintain the value of the variable?
2 Answers
If you define a variable my_variable in a module called my_module.py and it has been initialized, you can access to it from another module:
from my_module import my_variable
You can also do:
import my_module
...
my_module.my_variable
but I recommend the first option if you only need that variable from my_module.py
from my_file import my_variable?xin a file saytest.py, you can import it in another file likeimport test,test.x