Use "with" to open and close input files
This commit is contained in:
parent
b726afbb5a
commit
d09cd0f197
1 changed files with 40 additions and 42 deletions
|
@ -206,7 +206,7 @@ def convert(images, dpi, x, y, title=None, author=None, creator=None, producer=N
|
|||
|
||||
for imfilename in images:
|
||||
debug_out("Reading %s"%imfilename, verbose)
|
||||
im = open(imfilename, "rb")
|
||||
with open(imfilename, "rb") as im:
|
||||
rawdata = im.read()
|
||||
im.seek(0)
|
||||
try:
|
||||
|
@ -286,8 +286,6 @@ def convert(images, dpi, x, y, title=None, author=None, creator=None, producer=N
|
|||
|
||||
pdf.addimage(color, width, height, imgformat, imgdata, pdf_x, pdf_y)
|
||||
|
||||
im.close()
|
||||
|
||||
return pdf.tostring()
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue