diff options
author | Stefan Behnel <stefan_ml@behnel.de> | 2019-02-17 08:26:59 +0100 |
---|---|---|
committer | Stefan Behnel <stefan_ml@behnel.de> | 2019-02-17 08:26:59 +0100 |
commit | c2f4cced65659a84fc502de087fe6f7969a9a6f8 (patch) | |
tree | 749a5e8aeb878da61498f50641ce07864fc395c8 /Cython | |
parent | f1eaa9c1f8c37d8679a259982ee9949676952f0e (diff) | |
download | cython-c2f4cced65659a84fc502de087fe6f7969a9a6f8.tar.gz |
Minor code modernisations in Tempita module to use the with-statement.
Diffstat (limited to 'Cython')
-rw-r--r-- | Cython/Tempita/_tempita.py | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/Cython/Tempita/_tempita.py b/Cython/Tempita/_tempita.py index 32a3e493d..103bc9110 100644 --- a/Cython/Tempita/_tempita.py +++ b/Cython/Tempita/_tempita.py @@ -146,9 +146,8 @@ class Template(object): def from_filename(cls, filename, namespace=None, encoding=None, default_inherit=None, get_template=get_file_template): - f = open(filename, 'rb') - c = f.read() - f.close() + with open(filename, 'rb') as f: + c = f.read() if encoding: c = c.decode(encoding) return cls(content=c, name=filename, namespace=namespace, @@ -1164,9 +1163,8 @@ def fill_command(args=None): template_content = sys.stdin.read() template_name = '<stdin>' else: - f = open(template_name, 'rb') - template_content = f.read() - f.close() + with open(template_name, 'rb') as f: + template_content = f.read() if options.use_html: TemplateClass = HTMLTemplate else: @@ -1174,9 +1172,8 @@ def fill_command(args=None): template = TemplateClass(template_content, name=template_name) result = template.substitute(vars) if options.output: - f = open(options.output, 'wb') - f.write(result) - f.close() + with open(options.output, 'wb') as f: + f.write(result) else: sys.stdout.write(result) |