我需要脚本遍历文件的每一行,如果它从excel中找到一个值,它就会替换它
File:
Port 1/1/1\n
Description xxx\n
Port 2/1/3\n
Description yyy\n
Port 3/4/2\n
Description zzz\n
Excel:
1/1/1 - 5/5/5
3/4/2 - 6/6/6
我只能从文件中找到值。但我不知道怎么做替换。有什么想法吗?
import re
import pandas
excel_data_df = pandas.read_excel('swap_ports.xlsx', sheet_name='ports')
print(excel_data_df)
with open("string.txt", "r") as f:
pattern = r'\d[/]\d[/]\w\d'
printlines = f.readlines()
for i in printlines:
results = re.findall(pattern, i)
print (results)
1条答案
按热度按时间uinbv5nw1#