Mercurial > python-cmd2
changeset 41:1275d59c08a7
do_load accepts file object
author | catherine@cordelia |
---|---|
date | Thu, 22 May 2008 20:07:07 -0400 |
parents | 4f2d6f9f2080 |
children | b3200c6e5763 |
files | cmd2.py |
diffstat | 1 files changed, 11 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/cmd2.py Tue May 20 21:50:00 2008 -0400 +++ b/cmd2.py Thu May 22 20:07:07 2008 -0400 @@ -487,15 +487,18 @@ if fname is None: fname = self.defaultFileName keepstate = Statekeeper(self, ('stdin','use_rawinput','prompt','continuationPrompt')) - try: - self.stdin = open(fname, 'r') - except IOError, e: + if isinstance(fname, file): + self.stdin = fname + else: try: - self.stdin = open('%s.%s' % (fname, self.defaultExtension), 'r') - except IOError: - print 'Problem opening file %s: \n%s' % (fname, e) - keepstate.restore() - return + self.stdin = open(fname, 'r') + except IOError, e: + try: + self.stdin = open('%s.%s' % (fname, self.defaultExtension), 'r') + except IOError: + print 'Problem opening file %s: \n%s' % (fname, e) + keepstate.restore() + return self.use_rawinput = False self.prompt = self.continuationPrompt = '' self.cmdloop()