diff options
Diffstat (limited to 'pygments/formatters/html.py')
-rw-r--r-- | pygments/formatters/html.py | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/pygments/formatters/html.py b/pygments/formatters/html.py index 2969d502..7d7605eb 100644 --- a/pygments/formatters/html.py +++ b/pygments/formatters/html.py @@ -535,10 +535,9 @@ class HtmlFormatter(Formatter): # write CSS file only if noclobber_cssfile isn't given as an option. try: if not os.path.exists(cssfilename) or not self.noclobber_cssfile: - cf = open(cssfilename, "w") - cf.write(CSSFILE_TEMPLATE % - {'styledefs': self.get_style_defs('body')}) - cf.close() + with open(cssfilename, "w") as cf: + cf.write(CSSFILE_TEMPLATE % + {'styledefs': self.get_style_defs('body')}) except IOError as err: err.strerror = 'Error writing CSS file: ' + err.strerror raise |