简体   繁体   English

从运行 python 脚本导入变量

[英]Import variable from running python script

Is it possible to import a variable from a running python script into another script.是否可以将正在运行的 python 脚本中的变量导入另一个脚本。 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.例如,加载一个神经网络 model 并在另一个脚本中使用它,以免每次启动时都加载它。

The are a lot of ways doing it, here are some of the most popular from easy to harder:有很多方法可以做到这一点,这里有一些最流行的,从容易到难:

  1. Save the variable into a file, read it from the other script.将变量保存到文件中,从其他脚本中读取。
  2. Save the variable into some kind of environment variable, use it from the second script.将变量保存到某种环境变量中,从第二个脚本中使用它。
  3. Open a socket between the scripts and communicate through it.在脚本之间打开一个套接字并通过它进行通信。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM