##// END OF EJS Templates
Inline trivial file_read() function
Thomas Kluyver -
Show More
@@ -27,7 +27,6 b' from IPython.core.oinspect import find_file, find_source_lines'
27 27 from IPython.testing.skipdoctest import skip_doctest
28 28 from IPython.utils import py3compat
29 29 from IPython.utils.contexts import preserve_keys
30 from IPython.utils.io import file_read
31 30 from IPython.utils.path import get_py_filename, unquote_filename
32 31 from IPython.utils.warn import warn
33 32
@@ -531,7 +530,8 b' class CodeMagics(Magics):'
531 530 # XXX TODO: should this be generalized for all string vars?
532 531 # For now, this is special-cased to blocks created by cpaste
533 532 if args.strip() == 'pasted_block':
534 self.shell.user_ns['pasted_block'] = file_read(filename)
533 with open(filename, 'r') as f:
534 self.shell.user_ns['pasted_block'] = f.read()
535 535
536 536 if 'x' in opts: # -x prevents actual execution
537 537 print
@@ -541,8 +541,9 b' class CodeMagics(Magics):'
541 541 if not is_temp:
542 542 self.shell.user_ns['__file__'] = filename
543 543 if 'r' in opts: # Untranslated IPython code
544 self.shell.run_cell(file_read(filename),
545 store_history=False)
544 with open(filename, 'r') as f:
545 source = f.read()
546 self.shell.run_cell(source, store_history=False)
546 547 else:
547 548 self.shell.safe_execfile(filename, self.shell.user_ns,
548 549 self.shell.user_ns)
@@ -184,7 +184,6 b' import shlex'
184 184 import sys
185 185
186 186 from IPython.utils import io
187 from IPython.utils.io import file_read
188 187 from IPython.utils.text import marquee
189 188 from IPython.utils import openpy
190 189 __all__ = ['Demo','IPythonDemo','LineDemo','IPythonLineDemo','DemoError']
@@ -380,7 +379,8 b' class Demo(object):'
380 379
381 380 filename = self.shell.mktempfile(self.src_blocks[index])
382 381 self.shell.hooks.editor(filename,1)
383 new_block = file_read(filename)
382 with open(filename, 'r') as f:
383 new_block = f.read()
384 384 # update the source and colored block
385 385 self.src_blocks[index] = new_block
386 386 self.src_blocks_colored[index] = self.ip_colorize(new_block)
@@ -154,22 +154,6 b' class Tee(object):'
154 154 self.close()
155 155
156 156
157 def file_read(filename):
158 """Read a file and close it. Returns the file source."""
159 fobj = open(filename,'r');
160 source = fobj.read();
161 fobj.close()
162 return source
163
164
165 def file_readlines(filename):
166 """Read a file and close it. Returns the file source using readlines()."""
167 fobj = open(filename,'r');
168 lines = fobj.readlines();
169 fobj.close()
170 return lines
171
172
173 157 def raw_input_multi(header='', ps1='==> ', ps2='..> ',terminate_str = '.'):
174 158 """Take multiple lines of input.
175 159
General Comments 0
You need to be logged in to leave comments. Login now