Message399361
Sometimes bad things happen when processing an in-place filter, leaving an empty or incomplete input file and a backup file that needs to recovered. The FileInput class has all the information needed to do this, but it is in private instance variables. A .rollback() method could close the current file and rename the backup file to its original name. For example:
for line in fileinput.input(inplace=True):
try:
...
except SomeError:
fileinput.rollback(close=False) # continue with next file
A simplistic implementation could be:
def rollback(self, close=True):
if self._backupfilename:
os.rename(self._backupfilename, self.filename)
self._backupfilename = None
if close:
self.close()
else:
self.nextfile() |
|
Date |
User |
Action |
Args |
2021-08-10 22:22:25 | samwyse | set | recipients:
+ samwyse |
2021-08-10 22:22:25 | samwyse | set | messageid: <1628634145.27.0.557852545267.issue44882@roundup.psfhosted.org> |
2021-08-10 22:22:25 | samwyse | link | issue44882 messages |
2021-08-10 22:22:25 | samwyse | create | |
|