Is it possible to import a variable from a running python script into another script. Something like notebooks cells, but with scripts. For example, load a neural network model and use it in another script so as not to load it every time it starts.
Asked
Active
Viewed 111 times
0
-
Does this answer your question? [Using global variables between files?](https://stackoverflow.com/questions/13034496/using-global-variables-between-files) – Tomerikoo Mar 01 '21 at 08:23
-
please elaborate your sentence. – Elvin Jafarov Mar 01 '21 at 08:24
-
try https://stackoverflow.com/questions/6920858/interprocess-communication-in-python – Daniel Nudelman Mar 01 '21 at 08:24
-
@Elvin Jafarov Clarified – Nikita Romanov Mar 01 '21 at 08:30
-
You should look into the [`pickle`](https://docs.python.org/3/library/pickle.html) module – Abdul Aziz Barkat Mar 01 '21 at 08:33
-
use pickle module – Elvin Jafarov Mar 01 '21 at 08:37
-
Thanks everyone for the answers – Nikita Romanov Mar 01 '21 at 10:57
1 Answers
0
The are a lot of ways doing it, here are some of the most popular from easy to harder:
- Save the variable into a file, read it from the other script.
- Save the variable into some kind of environment variable, use it from the second script.
- Open a socket between the scripts and communicate through it.

Daniel Nudelman
- 401
- 5
- 11