【发布时间】:2020-12-22 11:50:57
【问题描述】:
我在 Python 脚本 1.py 中有以下代码,它在运行时执行 read_config.rb ruby 脚本。
from Naked.toolshed.shell import execute_rb, muterun_rb
success = execute_rb('read_config.rb')
现在这里是一个 read_config.rb Ruby 文件
from my-vpc-netapp-only import Variables # Python line of code to be executed
require 'erb'
require 'yaml'
region= 'ap-south-1'
k8sver='1.18'
vpccidr= '192.168.0.0/16'
vpcid = Variables.VPC_ID
pubsubnet1a = Variables.PUBSUBNET1A
pubsubnet1b = Variables.PUBSUBNET1B
prisubnet1a = Variables.PRISUBNET1A
prisubnet1b = Variables.PRISUBNET1B
template = ERB.new File.read 'managedcluster.yaml.erb'
File.open('managedcluster.yaml', 'w') do |f|
f.write template.result(binding)
end
在这个 Ruby 文件中,我从另一个 python 脚本中导入类变量。 可以进行哪些更改以使脚本执行时不会出现任何错误?
【问题讨论】:
-
请参阅decalage.info/python/ruby_bridge 以了解您的选项概述,我个人会在 Ruby 本身中从您的 netapp 读取变量,不需要 Python
-
为什么不直接将变量传递给 ruby 脚本呢?
from Naked.toolshed.shell import execute_rb, muterun_rb; from my-vpc-netapp-only import Variables; success = execute_rb('read_config.rb', [YOUR VARIABLES HERE])然后在 ruby 脚本中,您可以从ARGV读取它们。 Basic article on ARGV
标签: python ruby-on-rails ruby python-3.8