任何人都可以帮助将输出文件输出到变量
以下是文件输出:
SAN Image:
Type: Primary
VHBA: A
SAN Image Path:
Type: Primary
LUN: 0
WWN: 20:00:
Type: Secondary
LUN: 10
WWN: 20:00:
Type: Secondary
VHBA: B
SAN Image Path:
Type: Primary
LUN: 20
WWN: 30:00:
Type: Secondary
LUN: 20
WWN: 30:00:
在上面的文件中,我们有多个“Type:Primary”。
我使用下面的代码来分配变量:
search = "Type: Primary"
with open("file") as fin:
for line in fin:
if search == line:
vhba, ignore1, ignore2, lun1, wwn1, ignore3, lun2, wwn2 = islice(fin, 8)
print vhba
print wwn2
break
我期望下面的变量必须低于以下值:
vhba = A
lun1 = 10
wwn1 = 20:00:
wwn2 = 20:00:
(基本上这些值来自输出的前10行)
请帮助我了解如何获取这些值