From e14a0df100e896b3a36b1839a8a0863185857b35 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Wed, 29 Jun 2011 16:19:50 +0100 Subject: [PATCH] Use with to deal with an open file. --- vmdebootstrap | 5 ++--- 1 file 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']: -- 2.39.2