Skip to content

Instantly share code, notes, and snippets.

@tmaybe
Created February 24, 2013 05:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmaybe/5022681 to your computer and use it in GitHub Desktop.
Save tmaybe/5022681 to your computer and use it in GitHub Desktop.
Simple Python script for reading from a file, changing something about it with a regular expression, and writing the result to a new file.
import re
read_in = open("original.plist")
write_out = open("new.plist","w")
minus = 280
pat = re.compile('\t\t\t\t<real>([0-9]*)<')
for line in read_in:
mo = pat.search(line)
if mo:
value = int(mo.group(1))
writeme = "\t\t\t\t<real>" + str(value - minus) + "</real>\n"
write_out.write(writeme)
else:
write_out.write(line)
read_in.close()
write_out.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment