Nov-22-2018, 09:19 AM
Hey , i tried below
p = ['Eth1/1', 'Eth1/48','Eth2/1', 'Eth2/4','Eth101/1/1', 'Eth101/1/16', 'Eth101/1/3','Eth102/1/1', 'Eth102/1/2', 'Eth102/1/3','Eth103/1/1', 'Eth103/1/2', 'Eth103/1/3','Eth103/1/4','Eth104/1/1', 'Eth104/1/2', 'Eth104/1/3','Eth104/1/4'] with open("abc1.txt", "w+") as fw1, open("abc2.txt", "w+") as fw2: for element in p: if len(element.strip('Eth').split('/')[0]) == 1: # if you have one digit before the first / fw1.write('int ' + i + '\n mode\n') # write to abc1.txt else: # if you a sure that the input is correct else should work if you have three digits before / # write to abc2.txt fw2.write('int ' + i + '\n mode\n')both the file abc1.txt and abc2.txt contains
int Eth104/1/4 mode int Eth104/1/4 mode int Eth104/1/4 mode int Eth104/1/4 mode