diff options
author | Lars Wirzenius <liw@liw.fi> | 2011-06-29 16:19:50 +0100 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2011-06-29 16:19:50 +0100 |
commit | e14a0df100e896b3a36b1839a8a0863185857b35 (patch) | |
tree | d0fafb7a96fc11c64c3e68ff5c3782566493a700 | |
parent | 39a5154dfb8173800751e5ca6e938e63a3808b1e (diff) | |
download | vmdebootstrap-e14a0df100e896b3a36b1839a8a0863185857b35.tar.gz |
Use with to deal with an open file.
-rwxr-xr-x | vmdebootstrap | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/vmdebootstrap b/vmdebootstrap index 67e5a40..f859587 100755 --- a/vmdebootstrap +++ b/vmdebootstrap @@ -172,9 +172,8 @@ class VmDebootstrap(cliapp.Application): def set_hostname(self, rootdir): hostname = self.settings['hostname'] - f = open(os.path.join(rootdir, 'etc', 'hostname'), 'w') - f.write(hostname) - f.close() + with open(os.path.join(rootdir, 'etc', 'hostname'), 'w') as f: + f.write(hostname) def set_root_password(self, rootdir): if self.settings['root-password']: |