diff options
author | Lars Wirzenius <liw@liw.fi> | 2015-03-27 20:06:18 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2015-03-27 20:06:18 +0200 |
commit | 3e8bb3c6a264b0f525a52bcb363e99cb512d750e (patch) | |
tree | caba620cc071e0ad079eeaa791830db2c2b3c703 | |
parent | a55aa9249cc8e0126efa0c1f0df8cf9bd158f002 (diff) | |
download | genbackupdata-3e8bb3c6a264b0f525a52bcb363e99cb512d750e.tar.gz |
Refactor "f=open()...f.close()" to use "with open() as f:"
-rwxr-xr-x | genbackupdata | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/genbackupdata b/genbackupdata index 7ed1ee8..168961b 100755 --- a/genbackupdata +++ b/genbackupdata @@ -77,13 +77,12 @@ class GenbackupdataApp(cliapp.Application): dirname = os.path.dirname(pathname) if not os.path.exists(dirname): os.makedirs(dirname) - f = open(pathname, 'wb') - while bytes >= chunk_size: - self.write_bytes(f, chunk_size) - bytes -= chunk_size - if bytes > 0: - self.write_bytes(f, bytes) - f.close() + with open(pathname, 'wb') as f: + while bytes >= chunk_size: + self.write_bytes(f, chunk_size) + bytes -= chunk_size + if bytes > 0: + self.write_bytes(f, bytes) def write_bytes(self, f, bytes): chunk = self.gen.generate(bytes) |