From 15f8e057f1b5184abc11a6dac9295d3b9945e1a1 2012-04-26 16:44:00 From: Brandon Parsons Date: 2012-04-26 16:44:00 Subject: [PATCH] substitute open(...) for file(...) The file type is gone in py3k, and all file objects are under the new io hierarchy. Since open(...) is supported on both Python 2 and 3, use it instead of file in all instances. This isn't caught by 2to3. --- diff --git a/IPython/core/magic.py b/IPython/core/magic.py index 183cd89..b294a0f 100644 --- a/IPython/core/magic.py +++ b/IPython/core/magic.py @@ -613,7 +613,7 @@ Currently the magic system has the following functions:\n""" except IOError,msg: print msg return - page.page(self.shell.inspector.format(file(filename).read())) + page.page(self.shell.inspector.format(open(filename).read())) def magic_psearch(self, parameter_s=''): """Search for object in namespaces by wildcard. @@ -1541,7 +1541,7 @@ Currently the magic system has the following functions:\n""" `dump_file`+'.',sys_exit if text_file: text_file = unquote_filename(text_file) - pfile = file(text_file,'w') + pfile = open(text_file,'w') pfile.write(output) pfile.close() print '\n*** Profile printout saved to text file',\ diff --git a/IPython/core/page.py b/IPython/core/page.py index efee97e..2f93f40 100644 --- a/IPython/core/page.py +++ b/IPython/core/page.py @@ -203,7 +203,7 @@ def page(strng, start=0, screen_lines=0, pager_cmd=None): retval = 1 else: tmpname = tempfile.mktemp('.txt') - tmpfile = file(tmpname,'wt') + tmpfile = open(tmpname,'wt') tmpfile.write(strng) tmpfile.close() cmd = "%s < %s" % (pager_cmd,tmpname) diff --git a/IPython/external/path/_path.py b/IPython/external/path/_path.py index bdb1d05..4e4886e 100644 --- a/IPython/external/path/_path.py +++ b/IPython/external/path/_path.py @@ -602,7 +602,7 @@ class path(unicode): u'\x85', u'\r\x85', and u'\u2028'. (This is slightly different from when you open a file for - writing with fopen(filename, "w") in C or file(filename, 'w') + writing with fopen(filename, "w") in C or open(filename, 'w') in Python.) diff --git a/IPython/external/pexpect/_pexpect.py b/IPython/external/pexpect/_pexpect.py index 05babd6..50ae118 100644 --- a/IPython/external/pexpect/_pexpect.py +++ b/IPython/external/pexpect/_pexpect.py @@ -352,7 +352,7 @@ class spawnb(object): Example log input and output to a file:: child = pexpect.spawn('some_command') - fout = file('mylog.txt','w') + fout = open('mylog.txt','w') child.logfile = fout Example log to stdout:: diff --git a/IPython/frontend/terminal/interactiveshell.py b/IPython/frontend/terminal/interactiveshell.py index 1c3e13a..c29c1d2 100644 --- a/IPython/frontend/terminal/interactiveshell.py +++ b/IPython/frontend/terminal/interactiveshell.py @@ -472,7 +472,7 @@ class TerminalInteractiveShell(InteractiveShell): self.showtraceback() else: try: - f = file(err.filename) + f = open(err.filename) try: # This should be inside a display_trap block and I # think it is. diff --git a/IPython/utils/PyColorize.py b/IPython/utils/PyColorize.py index 8a5e70b..91943e4 100644 --- a/IPython/utils/PyColorize.py +++ b/IPython/utils/PyColorize.py @@ -281,7 +281,7 @@ If no filename is given, or if filename is -, read standard input.""" stream = sys.stdin else: try: - stream = file(fname) + stream = open(fname) except IOError,msg: print >> sys.stderr, msg sys.exit(1) diff --git a/IPython/zmq/kernelapp.py b/IPython/zmq/kernelapp.py index bc112f3..e7eec92 100644 --- a/IPython/zmq/kernelapp.py +++ b/IPython/zmq/kernelapp.py @@ -251,7 +251,7 @@ class KernelApp(BaseIPythonApplication): def init_blackhole(self): """redirects stdout/stderr to devnull if necessary""" if self.no_stdout or self.no_stderr: - blackhole = file(os.devnull, 'w') + blackhole = open(os.devnull, 'w') if self.no_stdout: sys.stdout = sys.__stdout__ = blackhole if self.no_stderr: