以下是输入数据:
crypto map outside_map0 1 set peer 1.1.1.1
crypto map outside_map0 1 ikev1 transform-set ESP-AES-256-SHA
crypto map outside_map0 2 set peer 2.2.2.2
crypto map outside_map0 2 ikev1 transform-set ESP-AES-256-SHA
crypto map outside_map0 3 set peer 3.3.3.3
crypto map outside_map0 3 ikev1 transform-set ESP-AES-256-SHA
crypto map outside_map0 4 set peer 4.4.4.4
crypto map outside_map0 4 ikev1 transform-set ESP-3DES-SHA
我希望输出数据如下所示:
1, 1.1.1.1, ESP-AES-256-SHA
2, 2.2.2.2, ESP-AES-256-SHA
3, 3.3.3.3, ESP-AES-256-SHA
4, 4.4.4.4, ESP-3DES-SHA
我现在的剧本是这样的:
fo = open('vpn.txt', 'r')
for line in fo.readlines():
list = line.split(" ")
if "peer" in list:
print list[3] + "," + list[6] + "," + next(list[6])
我很难理解下一个函数的用法。你知道吗
不能在str对象旁边使用。你知道吗
下面是一个精确文件结构的解决方案
参见问题How do I read two lines from a file at a time using python
这只是每行的最后一个字,一次两行。您还需要执行一些错误检查,如
或者试图parse ^{} as an IP address
使用
next
函数可以做你想做的事情,但这不是解决这个问题的最简单、最容易理解的方法。我不建议在这里尝试使用next
。你知道吗您在文件中的行上有一个
for
循环,但是您确实希望一次读取两行,因为每个“项”数据都依赖于文件中的两行。我建议分三个部分来解决这个问题:while
循环,一次读取文件的两行,从这两行中提取数据以创建一个对象,并在列表中收集这些对象。你知道吗第2部分的解决方案如下所示:
相关问题 更多 >
编程相关推荐