Use a context manager for some file objects.

This commit is contained in:
Florent Xicluna 2010-09-03 19:52:03 +00:00
parent 24e561ae04
commit 7dde792e62
4 changed files with 20 additions and 32 deletions

View file

@ -155,21 +155,15 @@ class Pdb(bdb.Bdb, cmd.Cmd):
if 'HOME' in os.environ:
envHome = os.environ['HOME']
try:
rcFile = open(os.path.join(envHome, ".pdbrc"))
with open(os.path.join(envHome, ".pdbrc")) as rcFile:
self.rcLines.extend(rcFile)
except IOError:
pass
else:
for line in rcFile.readlines():
self.rcLines.append(line)
rcFile.close()
try:
rcFile = open(".pdbrc")
with open(".pdbrc") as rcFile:
self.rcLines.extend(rcFile)
except IOError:
pass
else:
for line in rcFile.readlines():
self.rcLines.append(line)
rcFile.close()
self.commands = {} # associates a command list to breakpoint numbers
self.commands_doprompt = {} # for each bp num, tells if the prompt