From 39a72e3355a4c6003de954b3300618019e537219 Mon Sep 17 00:00:00 2001 From: Horea Christian Date: Sat, 2 Jan 2021 23:47:54 -0500 Subject: [PATCH] Python 3 syntax for print calls --- README.md | 2 +- archiver.py | 4 ++-- doc_sphinx/sphinxext/apigen.py | 2 +- doc_sphinx/sphinxext/docscrape.py | 13 +++++-------- .../sphinxext/ipython_console_highlighting.py | 2 +- doc_sphinx/sphinxext/numpydoc.py | 4 ++-- matrix2latex/matrix2latex.py | 2 +- matrix2latex/render.py | 2 +- test/test.py | 16 ++++++++-------- test/testVersionCompatibility.py | 2 +- 10 files changed, 23 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 9baa94e..671350f 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ The following python code: from matrix2latex import matrix2latex m = [[1, 1], [2, 4], [3, 9]] # python nested list t = matrix2latex(m) -print t +print(t) ``` or equivalent matlab code: ```matlab diff --git a/archiver.py b/archiver.py index 78dd533..6e44091 100755 --- a/archiver.py +++ b/archiver.py @@ -5,10 +5,10 @@ import os def callSystem(command): - print '>' + command + print('>' + command) ret = os.system(command) if ret != 0: - print 'Command failed, exiting' + print('Command failed, exiting') exit(1) version = '1.0.0' diff --git a/doc_sphinx/sphinxext/apigen.py b/doc_sphinx/sphinxext/apigen.py index 1237409..185d327 100644 --- a/doc_sphinx/sphinxext/apigen.py +++ b/doc_sphinx/sphinxext/apigen.py @@ -206,7 +206,7 @@ def generate_api_doc(self, uri): # get the names of all classes and functions functions, classes = self._parse_module(uri) if not len(functions) and not len(classes): - print 'WARNING: Empty -',uri # dbg + print('WARNING: Empty -',uri) # dbg return '' # Make a shorter version of the uri that omits the package name for diff --git a/doc_sphinx/sphinxext/docscrape.py b/doc_sphinx/sphinxext/docscrape.py index f374b3d..8c3a2dc 100644 --- a/doc_sphinx/sphinxext/docscrape.py +++ b/doc_sphinx/sphinxext/docscrape.py @@ -414,12 +414,9 @@ def __init__(self, func, role='func', doc=None): try: NumpyDocString.__init__(self, doc) except ValueError, e: - print '*'*78 - print "ERROR: '%s' while parsing `%s`" % (e, self._f) - print '*'*78 - #print "Docstring follows:" - #print doclines - #print '='*78 + print('*'*78) + print("ERROR: '%s' while parsing `%s`" % (e, self._f)) + print('*'*78) if not self['Signature']: func, func_name = self.get_func() @@ -452,7 +449,7 @@ def __str__(self): if self._role: if not roles.has_key(self._role): - print "Warning: invalid role %s" % self._role + print("Warning: invalid role %s" % self._role) out += '.. %s:: %s\n \n\n' % (roles.get(self._role,''), func_name) @@ -488,7 +485,7 @@ def __str__(self): out += "\n\n" #for m in self.methods: - # print "Parsing `%s`" % m + # print("Parsing `%s`" % m) # out += str(self._func_doc(getattr(self._cls,m), 'meth')) + '\n\n' # out += '.. index::\n single: %s; %s\n\n' % (self._name, m) diff --git a/doc_sphinx/sphinxext/ipython_console_highlighting.py b/doc_sphinx/sphinxext/ipython_console_highlighting.py index 217b779..9e169c0 100644 --- a/doc_sphinx/sphinxext/ipython_console_highlighting.py +++ b/doc_sphinx/sphinxext/ipython_console_highlighting.py @@ -37,7 +37,7 @@ class IPythonConsoleLexer(Lexer): In [2]: a Out[2]: 'foo' - In [3]: print a + In [3]: print(a) foo In [4]: 1 / 0 diff --git a/doc_sphinx/sphinxext/numpydoc.py b/doc_sphinx/sphinxext/numpydoc.py index ff6c44c..eea482d 100644 --- a/doc_sphinx/sphinxext/numpydoc.py +++ b/doc_sphinx/sphinxext/numpydoc.py @@ -49,7 +49,7 @@ def mangle_docstrings(app, what, name, obj, options, lines, try: references.append(int(l[len('.. ['):l.index(']')])) except ValueError: - print "WARNING: invalid reference in %s docstring" % name + print("WARNING: invalid reference in %s docstring" % name) # Start renaming from the biggest number, otherwise we may # overwrite references. @@ -104,7 +104,7 @@ def monkeypatch_sphinx_ext_autodoc(): if sphinx.ext.autodoc.format_signature is our_format_signature: return - print "[numpydoc] Monkeypatching sphinx.ext.autodoc ..." + print("[numpydoc] Monkeypatching sphinx.ext.autodoc ...") _original_format_signature = sphinx.ext.autodoc.format_signature sphinx.ext.autodoc.format_signature = our_format_signature diff --git a/matrix2latex/matrix2latex.py b/matrix2latex/matrix2latex.py index 921383a..abc205b 100644 --- a/matrix2latex/matrix2latex.py +++ b/matrix2latex/matrix2latex.py @@ -450,4 +450,4 @@ def matrix2latex(matr, filename=None, *environments, **keywords): # TODO: # m = [[1], [2,2,1], [2,1,2]] -# print matrix2latex(m, transpose=True) +# print(matrix2latex(m, transpose=True)) diff --git a/matrix2latex/render.py b/matrix2latex/render.py index a38fbe0..f4df40b 100644 --- a/matrix2latex/render.py +++ b/matrix2latex/render.py @@ -138,7 +138,7 @@ def matrix2image(matr, filename=None, *args, **kwargs): if not(os.path.exists(output_filename_tmp)): raise IOError('Expected %s to exist after calling %s' % (output_filename_tmp, cmd)) - print output_filename_tmp, output_filename_final + print(output_filename_tmp, output_filename_final) shutil.copyfile(output_filename_tmp, output_filename_final) if clean_latex: diff --git a/test/test.py b/test/test.py index 6881efd..d1f5966 100755 --- a/test/test.py +++ b/test/test.py @@ -201,8 +201,8 @@ def test_pandas_dataframe(): m = [[1, 1], [2, 4], [3, 9]] # python nested list m = pd.DataFrame(m) #m = pd.DataFrame.from_csv('http://chymera.eu/data/test/r_data.csv', parse_dates=False, index_col=False) - # print 'PANDAS\n', m - # print 'PANDAS\n', m.to_records() + # print('PANDAS\n', m) + # print('PANDAS\n', m.to_records()) t = matrix2latex(m) assertEqual(t, "pandas_dataframe") except ImportError: @@ -213,12 +213,12 @@ def test_pandas_series(): import pandas as pd import numpy as np s = pd.Series([2, 4, 2, 42, 5], index=['a', 'b', 'c', 'd', 'e']) - # print 'PANDAS\n', s - # print 'PANDAS\n', s.to_dict(), s.tolist(), hasattr(s, 'to_dict') + # print('PANDAS\n', s) + # print('PANDAS\n', s.to_dict(), s.tolist(), hasattr(s, 'to_dict')) t = matrix2latex(s) - # print 'pandas Series', t + # print('pandas Series', t) t2 = matrix2latex(pd.DataFrame(s)) - # print 'pandas DataFrame', t2 + # print('pandas DataFrame', t2) assertEqual(t, "pandas_series") assertEqual(t2, "pandas_series_dataFrame") except ImportError: @@ -232,7 +232,7 @@ def test_pandas_columns(): 'two' : pd.Series([1., 2., 3., 4.], index=['a', 'b', 'c', 'd'])} df = pd.DataFrame(d) t = matrix2latex(df) - # print 'pandas', t, df.to_records() + # print('pandas', t, df.to_records()) assertEqual(t, "pandas_columns") t = matrix2latex(df, headerRow=None, headerColumn=None) @@ -250,7 +250,7 @@ def test_pandas_Panel(): frame = panel.to_frame() # TODO: Needs support for multiple headerColumns #t = matrix2latex(frame) - #print t + #print(t) #assert False except ImportError: pass diff --git a/test/testVersionCompatibility.py b/test/testVersionCompatibility.py index 941cc88..c2a6d0c 100755 --- a/test/testVersionCompatibility.py +++ b/test/testVersionCompatibility.py @@ -53,4 +53,4 @@ def test(python, table, pythonVersions): compatibleTable = matrix2latex(table, '../doc/compatibleTable', headerColumn=pythonVersions, headerRow=['Compatible'], caption=c) -print compatibleTable +print(compatibleTable)