Commit a074dafc by cclauss Committed by Tianqi Chen

Use print() function in both Python 2 and Python 3 (#3440)

Discovered via: __flake8 . --count --select=E9,F63,F72,F82 --show-source --statistics__

Legacy __print__ statements are syntax errors in Python 3 but __print()__ function works as expected in both Python 2 and Python 3.
parent 5abbeb7e
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the # KIND, either express or implied. See the License for the
# specific language governing permissions and limitations # specific language governing permissions and limitations
# under the License. # under the License.
from __future__ import print_function
import sys import sys
import os.path, re, StringIO import os.path, re, StringIO
...@@ -69,21 +70,21 @@ def expand(x, pending): ...@@ -69,21 +70,21 @@ def expand(x, pending):
return return
if x in pending: if x in pending:
#print 'loop found: %s in ' % x, pending #print('loop found: %s in ' % x, pending)
return return
print >>out, "//===== EXPANDING: %s =====\n" %x print("//===== EXPANDING: %s =====\n" % x, file=out)
for line in open(x): for line in open(x):
if line.find('#include') < 0: if line.find('#include') < 0:
out.write(line) out.write(line)
continue continue
if line.strip().find('#include') > 0: if line.strip().find('#include') > 0:
print line print(line)
continue continue
m = re1.search(line) m = re1.search(line)
if not m: m = re2.search(line) if not m: m = re2.search(line)
if not m: if not m:
print line + ' not found' print(line + ' not found')
continue continue
h = m.groups()[0].strip('./') h = m.groups()[0].strip('./')
source = find_source(h, x) source = find_source(h, x)
...@@ -94,7 +95,7 @@ def expand(x, pending): ...@@ -94,7 +95,7 @@ def expand(x, pending):
'nnpack' not in h): sysheaders.append(h) 'nnpack' not in h): sysheaders.append(h)
else: else:
expand(source, pending + [x]) expand(source, pending + [x])
print >>out, "//===== EXPANDED: %s =====\n" %x print("//===== EXPANDED: %s =====\n" % x, file=out)
history.add(x) history.add(x)
...@@ -105,12 +106,12 @@ f = open(sys.argv[3], 'wb') ...@@ -105,12 +106,12 @@ f = open(sys.argv[3], 'wb')
for k in sorted(sysheaders): for k in sorted(sysheaders):
print >>f, "#include <%s>" % k print("#include <%s>" % k, file=f)
print >>f, '' print('', file=f)
print >>f, out.getvalue() print(out.getvalue(), file=f)
for x in sources: for x in sources:
if x not in history and not x.endswith('.o'): if x not in history and not x.endswith('.o'):
print 'Not processed:', x print('Not processed:', x)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment