Skip to content

Instantly share code, notes, and snippets.

@SeqviriouM
Last active December 26, 2015 05:19
Show Gist options
  • Save SeqviriouM/7100356 to your computer and use it in GitHub Desktop.
Save SeqviriouM/7100356 to your computer and use it in GitHub Desktop.
Homework_1
import re
error = re.compile("<(kernel|initrd|cmdline)>.*$")
boot = re.compile("<boot dev='hd'/>.*$")
fr = open('input.xml','r')
fw = open('output.xml','w')
not_change = True
exist = False
for i in fr:
if boot.search(i) != None:
not_change = False
fr.close()
fr = open('input.xml','r')
if not exist:
for line in fr:
if error.search(line) == None:
fw.write(line)
else:
if (not_change):
line = error.sub("<boot dev='hd'/>",line)
fw.write(line)
not_change = False
fw.close()
fr.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment