# Your super node dictionnary
super_node = {'name': [...]}
new_text = ''
# Open your txt file
with open('test.txt') as f:
for line in f.readlines():
# Split each line
splitted = line.split(':')
for n, n_list in super_node.items():
if splitted[0] in n_list: # Source is in super node
splitted[0] = n # Replace node name
if splitted[1] in n_list: # Destination is in super node
splitted[1] = n # Replace node name
# Add to new text
new_text += '{0}\n'.format(':'.join(splitted))
# Write text file
with open('text.txt', 'w') as f:
f.write(new_text)
相关问题 更多 >
编程相关推荐