When I run the following script, a .bak backup file is left in the filesystem.
How do I close() the files(s) properly so the backups are deleted?
#!C:\Python27\python.exe
import os
myRelease = os.environ.get("BUILD_STRING")
myVersion = os.environ.get("VERSION_STRING")
import fileinput
import re
files = ["C:\Projects\FileToSub.sbs"]
for line in fileinput.FileInput(files,inplace=1):
line = re.sub('whatever, thing', line)
print line,
The
fileinputmodule takes care about deleting the backup files.I’m not completely sure what you tested, but your python code contains errors. A ‘guessed’ and ‘corrected’ version:
In the strace output you can see, that the files are automagically removed: