I'm trying to go through a bunch of files in a directory and find and replace a list of strings and write them to the same file. When I run the scripts all the files in the directory turn out blank! What am I doing wrong here?
os.chdir("Resources/maps_sideScrolling/HD")
replacements = {'tilewidth=\"16\"':'tilewidth=\"32\"', 'tileheight=\"16\"':'tileheight=\"32\"', '.png':'-hd.png'}
for files in os.listdir("."):
if files.endswith("-hd.tmx"):
fo = open(files, "rU")
fw = open(files, "w")
for line in fo:
for src, target in replacements.iteritems():
line = line.replace(src, target)
fw.write(line)
fo.close();
fw.close();