Commit 3c94b18d authored by Daniel Brown's avatar Daniel Brown
Browse files

fixing too many file open errors

parent 7d635b06
......@@ -3,7 +3,7 @@ from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
__version__ = "1.0.11"
__version__ = "1.0.13"
# This flag is used to switch on the gui features in pkat at import time
USE_GUI = False
......
......@@ -924,7 +924,9 @@ class kat(object):
`^-....____: +. {1}\n""".format(pykat.__version__, pykat_web))
def loadKatFile(self, katfile, blocks=None):
commands=open(katfile).read()
with open(katfile) as f:
commands= f.read()
self.parseCommands(commands, blocks=blocks)
def parseKatCode(self, code, blocks=None):
......@@ -1444,11 +1446,10 @@ class kat(object):
Saves the current kat object to a Finesse input file
"""
try:
katScript = "".join(self.generateKatScript())
katfile = open(filename,'w')
katfile.writelines(katScript)
katfile.flush()
katfile.close()
with open(filename,'w') as katfile:
katScript = "".join(self.generateKatScript())
katfile.writelines(katScript)
katfile.flush()
except pkex.BasePyKatException as ex:
print (ex)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment