diff options
Diffstat (limited to 'doc/numpybook/runcode.py')
-rw-r--r-- | doc/numpybook/runcode.py | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/doc/numpybook/runcode.py b/doc/numpybook/runcode.py index 92784d34e..456846cad 100644 --- a/doc/numpybook/runcode.py +++ b/doc/numpybook/runcode.py @@ -14,20 +14,20 @@ Options: -n name of code section (default MyCode) """ -from __future__ import division +from __future__ import division, absolute_import, print_function import sys import optparse -import cStringIO +import io import re import os newre = re.compile(r"\\begin_inset Note.*PYNEW\s+\\end_inset", re.DOTALL) def getoutput(tstr, dic): - print "\n\nRunning..." - print tstr, - tempstr = cStringIO.StringIO() + print("\n\nRunning...") + print(tstr, end=' ') + tempstr = io.StringIO() sys.stdout = tempstr code = compile(tstr, '<input>', 'exec') try: @@ -44,8 +44,8 @@ def getoutput(tstr, dic): else: res = tempstr.getvalue() + '\n' + repr(res) if res != '': - print "\nOutput is" - print res, + print("\nOutput is") + print(res, end=' ') return res # now find the code in the code segment @@ -82,7 +82,7 @@ def getnewcodestr(substr, dic): def runpycode(lyxstr, name='MyCode'): schobj = re.compile(r"\\layout %s\s+>>> " % name) - outstr = cStringIO.StringIO() + outstr = io.StringIO() num = 0 indx = [] for it in schobj.finditer(lyxstr): @@ -90,7 +90,7 @@ def runpycode(lyxstr, name='MyCode'): num += 1 if num == 0: - print "Nothing found for %s" % name + print("Nothing found for %s" % name) return lyxstr start = 0 @@ -141,7 +141,7 @@ def main(args): fid = file(args[0]) str = fid.read() fid.close() - print "Processing %s" % options.name + print("Processing %s" % options.name) newstr = runpycode(str, options.name) fid = file(args[0],'w') fid.write(newstr) |