[gimp] Use the "with" keyword when dealing with file objects
- From: Jehan <jehanp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] Use the "with" keyword when dealing with file objects
- Date: Sat, 29 Sep 2018 20:37:33 +0000 (UTC)
commit 04688c311195d07a8f0d3d46dbbe39b2d7c89972
Author: Michal <m powalko gmail com>
Date: Mon Sep 17 14:38:01 2018 +0200
Use the "with" keyword when dealing with file objects
According to: https://docs.python.org/3.6/tutorial/inputoutput.html
plug-ins/pygimp/plug-ins/file-openraster.py | 22 ++++++++++------------
1 file changed, 10 insertions(+), 12 deletions(-)
---
diff --git a/plug-ins/pygimp/plug-ins/file-openraster.py b/plug-ins/pygimp/plug-ins/file-openraster.py
index 586356f37d..b945fd8fbe 100755
--- a/plug-ins/pygimp/plug-ins/file-openraster.py
+++ b/plug-ins/pygimp/plug-ins/file-openraster.py
@@ -86,9 +86,8 @@ def thumbnail_ora(filename, thumb_size):
# create temp file
tmp = os.path.join(tempdir, 'tmp.png')
- f = open(tmp, 'wb')
- f.write(orafile.read('Thumbnails/thumbnail.png'))
- f.close()
+ with open(tmp, 'wb') as fid:
+ fid.write(orafile.read('Thumbnails/thumbnail.png'))
img = pdb['file-png-load'](tmp)
# TODO: scaling
@@ -287,15 +286,14 @@ def load_ora(filename, raw_filename):
# create temp file. Needed because gimp cannot load files from inside a zip file
tmp = os.path.join(tempdir, 'tmp.png')
- f = open(tmp, 'wb')
- try:
- data = orafile.read(path)
- except KeyError:
- # support for bad zip files (saved by old versions of this plugin)
- data = orafile.read(path.encode('utf-8'))
- print 'WARNING: bad OpenRaster ZIP file. There is an utf-8 encoded filename that does not
have the utf-8 flag set:', repr(path)
- f.write(data)
- f.close()
+ with open(tmp, 'wb') as fid:
+ try:
+ data = orafile.read(path)
+ except KeyError:
+ # support for bad zip files (saved by old versions of this plugin)
+ data = orafile.read(path.encode('utf-8'))
+ print 'WARNING: bad OpenRaster ZIP file. There is an utf-8 encoded filename that does
not have the utf-8 flag set:', repr(path)
+ fid.write(data)
# import layer, set attributes and add to image
gimp_layer = pdb['gimp-file-load-layer'](img, tmp)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]