问题陈述: 使用python
在oracle linux 7中安装软件包的脚本方案: 我有一个文本文件" oracle_package-requirement.txt" - >包含包名称 我正在使用以下程序使用以下代码将其附加到列表类型变量:
导入操作系统 f = open(" /home/dipesh/oracle_package_requirement.txt" ;," r") myList = [] 对于f中的行: myList.append(线)
所以我对社区的问题是如何在我的python代码中写这个????
答案 0 :(得分:0)
您可以使用子流程模块:
import os
import subprocess
f = open("/home/dipesh/oracle_package_requirement.txt","r")
myList = []
for line in f:
myList.append(line.strip()) # strip to get rid of trailing newline
subprocess.check_call(['yum', '-y', 'install'] + myList)