Last active
December 26, 2015 05:19
-
-
Save SeqviriouM/7100356 to your computer and use it in GitHub Desktop.
Homework_1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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