在写Python脚本时,我们可能希望从另一个脚本里面导入变量,分享下方法

文件A名为test1.py,变量名为localhost_hostname

localhost_hostname = run_cmd("cat /etc/host_name")[1]

文件B名为test2.py,需要使用到文件A名为test1.py文件里面的localhost_name变量

from test1 import localhost_hostname
print(localhost_hostname)

 

相关文章:

  • 2022-12-23
  • 2022-01-13
  • 2021-10-13
  • 2022-01-27
  • 2021-11-12
  • 2021-12-04
  • 2022-02-13
  • 2021-08-11
猜你喜欢
  • 2021-12-24
  • 2022-01-05
  • 2021-11-28
  • 2021-06-05
  • 2021-07-07
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案