我想在 Ruby 脚本中编写一段 python 代码,该怎么做?
I want to write a python code in Ruby script, how can that be done?
我在 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 脚本导入 class 变量。
可以进行哪些更改以使脚本无误地执行?
In this ruby file i am importing class Variables from another python script. What changes could be made to so that scripts get executed without any error ?
该行在语法上无效 Ruby,因此您需要做的第一件事就是修改它,使其变得有效 Ruby。也许是这样的:
import(:Variables, from: :'my-vpc-netapp-only')
第 2 步是在 Ruby 中编写一个 Python 解释器,它提供了一个 import
方法,可以将 Python 模块导入为 Ruby 对象。
据我了解,my-vpc-netapp-only
是一个 运行 应用程序,这就是为什么您需要使用等效导入自动获取变量值的原因。否则你可以从 my-vpc-netapp-only.py
中挑选一些变量。在那个假设下,这是写作的问题
PUBSUBNET1A
PUBSUBNET1B
PRISUBNET1A
PRISUBNET1B
当文件发生变化时 运行 my-vpc-netapp-only.py
并在 ruby 脚本中读取它以生成 yaml 文件。
我在 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 脚本导入 class 变量。 可以进行哪些更改以使脚本无误地执行?
In this ruby file i am importing class Variables from another python script. What changes could be made to so that scripts get executed without any error ?
该行在语法上无效 Ruby,因此您需要做的第一件事就是修改它,使其变得有效 Ruby。也许是这样的:
import(:Variables, from: :'my-vpc-netapp-only')
第 2 步是在 Ruby 中编写一个 Python 解释器,它提供了一个 import
方法,可以将 Python 模块导入为 Ruby 对象。
据我了解,my-vpc-netapp-only
是一个 运行 应用程序,这就是为什么您需要使用等效导入自动获取变量值的原因。否则你可以从 my-vpc-netapp-only.py
中挑选一些变量。在那个假设下,这是写作的问题
PUBSUBNET1A
PUBSUBNET1B
PRISUBNET1A
PRISUBNET1B
当文件发生变化时 运行 my-vpc-netapp-only.py
并在 ruby 脚本中读取它以生成 yaml 文件。