Read to local variable rather than double reading from file.
This commit is contained in:
parent
9b75cd0724
commit
42bdcc82e2
1 changed files with 4 additions and 3 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue