From: Lars Wirzenius Date: Wed, 29 Jun 2011 15:19:50 +0000 (+0100) Subject: Use with to deal with an open file. X-Git-Url: https://git.siccegge.de//index.cgi?p=forks%2Fvmdebootstrap.git;a=commitdiff_plain;h=e14a0df100e896b3a36b1839a8a0863185857b35 Use with to deal with an open file. --- 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']: