Use with open(...) as ...: context managers
Instead of manually opening and closes file objects, use the context manager that will properly handle opening and closing files for us, even in the event of some error
This commit is contained in:
@@ -88,15 +88,14 @@ def createFontBitmap(filename, fontname, fontsize, fontbold, foreground, backgro
|
||||
painter.end()
|
||||
image.save(filename + ".png")
|
||||
if coordsfile:
|
||||
f = file(filename + ".specs", "w")
|
||||
f.write("{ ")
|
||||
f.write(",".join(str(tmp) for tmp in coords))
|
||||
if extraWidth:
|
||||
for i in range(1, 14):
|
||||
f.write(", %d" % (int(coords[-1]) + i * (extraWidth / 12)))
|
||||
# f.write(file("fonts/extra_%dpx.specs" % fontsize).read())
|
||||
f.write(" }")
|
||||
f.close()
|
||||
with open(filename + ".specs", "w") as f:
|
||||
f.write("{ ")
|
||||
f.write(",".join(str(tmp) for tmp in coords))
|
||||
if extraWidth:
|
||||
for i in range(1, 14):
|
||||
f.write(", %d" % (int(coords[-1]) + i * (extraWidth / 12)))
|
||||
# f.write(file("fonts/extra_%dpx.specs" % fontsize).read())
|
||||
f.write(" }")
|
||||
return coords
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user