python - 我想用 Ruby 脚本编写一个 python 代码,怎么做?
问题描述
我在 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 脚本中导入类变量。可以进行哪些更改以使脚本在没有任何错误的情况下执行?
解决方案
据我了解,my-vpc-netapp-only
它是一个正在运行的应用程序,这就是为什么您需要使用导入等效项自动获取变量值的原因。否则,您可以从my-vpc-netapp-only.py
. 在那个假设中,这是一个写作问题
PUBSUBNET1A
PUBSUBNET1B
PRISUBNET1A
PRISUBNET1B
每当文件在运行时发生更改时my-vpc-netapp-only.py
,您就可以在 ruby 脚本中读取它以制作 yaml 文件。
推荐阅读
- javascript - 使用 Chart.js 的 onClick 函数,您可以从未定义或空结果执行代码吗?
- git - Git 不允许变基,因为没有分阶段的更改
- python - AttributeError:“AxesSubplot”对象没有属性“set_color_cycle”
- html - 图像 div 打破文本输入 HTML/CSS
- c# - C# 的最佳实践。用await传参数可以吗?
- python - 在渲染模板之前等待 MySQL 执行
- mysql - MYSQL - 搜索一些字符串
- amazon-web-services - 跨账户访问以在 CDK 中调用 AWS lambda
- excel-formula - Excel 公式查找第一个字符,然后查找数值
- python - OpenCV(Python)人脸检测程序未终止