Read to local variable rather than double reading from file.

This commit is contained in:
georgelinsdell 2017-12-20 15:58:54 +00:00
commit 42bdcc82e2

View file

@ -28,12 +28,13 @@ def main(argv):
with open(filetoconvert, 'x') as f:
with open(filecopy,'r') as c:
print("Detected %s instances of %s pre-conversion"%(c.read().count(pattern),pattern))
converted = c.read().replace(pattern, substitute)
fileread = c.read()
c.close()
print("Detected %s instances of %s pre-conversion"%(fileread.count(pattern),pattern))
converted = fileread.replace(pattern, substitute)
print ("DEBUG: %s "%converted)
print("Confirmed %s instances of %s post-conversion"%(converted.count(substitute),substitute))
f.write(converted)
c.close()
f.close()
return 0