diff options
author | hut <hut@lepus.uberspace.de> | 2016-04-15 14:43:56 +0200 |
---|---|---|
committer | hut <hut@lepus.uberspace.de> | 2016-04-15 14:43:56 +0200 |
commit | e50e61b2c39ff82df36620c23c126f62dcb04e19 (patch) | |
tree | 83241d6ffc1f13f25eed2412631103e9978a7e0e /ranger | |
parent | c3c2481ed1c780e9222dcc4e47d006ce5dbe81cc (diff) | |
download | ranger-e50e61b2c39ff82df36620c23c126f62dcb04e19.tar.gz |
core.actions: explicitly close file descriptor
Thanks to Ale1ster for pointing it out. Fixes #529
Diffstat (limited to 'ranger')
-rw-r--r-- | ranger/core/actions.py | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/ranger/core/actions.py b/ranger/core/actions.py index 3b1fc47a..ab97d81c 100644 --- a/ranger/core/actions.py +++ b/ranger/core/actions.py @@ -343,18 +343,19 @@ class Actions(FileManagerAware, SettingsAware): Load a config file. """ filename = os.path.expanduser(filename) - for line in open(filename, 'r'): - line = line.lstrip().rstrip("\r\n") - if line.startswith("#") or not line.strip(): - continue - try: - self.execute_console(line) - except Exception as e: - if ranger.arg.debug: - raise - else: - self.notify('Error in line `%s\':\n %s' % - (line, str(e)), bad=True) + with open(filename, 'r') as f: + for line in f: + line = line.lstrip().rstrip("\r\n") + if line.startswith("#") or not line.strip(): + continue + try: + self.execute_console(line) + except Exception as e: + if ranger.arg.debug: + raise + else: + self.notify('Error in line `%s\':\n %s' % + (line, str(e)), bad=True) def execute_file(self, files, **kw): """Uses the "rifle" module to open/execute a file |