Skip to content

Commit fe966bb

Browse files
javierhonducoyonghong-song
authored andcommitted
Use print function for Python 3 compatibility (iovisor#1748)
and add `from __future__ import print_function` where needed for Python3 print semantics in Python2
1 parent 0a43633 commit fe966bb

5 files changed

Lines changed: 16 additions & 11 deletions

File tree

‎examples/tracing/bitehist.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#
1414
# 15-Aug-2015 Brendan Gregg Created this.
1515

16+
from __future__ import print_function
1617
from bcc import BPF
1718
from time import sleep
1819

@@ -37,7 +38,7 @@
3738
try:
3839
sleep(99999999)
3940
except KeyboardInterrupt:
40-
print
41+
print()
4142

4243
# output
4344
b["dist"].print_log2_hist("kbytes")

‎examples/tracing/trace_fields.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
# run in project examples directory with:
77
# sudo ./trace_fields.py"
88

9+
from __future__ import print_function
910
from bcc import BPF
1011

1112
prog = """
@@ -16,5 +17,5 @@
1617
"""
1718
b = BPF(text=prog)
1819
b.attach_kprobe(event=b.get_syscall_fnname("clone"), fn_name="hello")
19-
print "PID MESSAGE"
20+
print("PID MESSAGE")
2021
b.trace_print(fmt="{1} {5}")

‎examples/tracing/vfsreadlat.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#
1616
# 15-Aug-2015 Brendan Gregg Created this.
1717

18+
from __future__ import print_function
1819
from bcc import BPF
1920
from ctypes import c_ushort, c_int, c_ulonglong
2021
from time import sleep
@@ -58,7 +59,7 @@ def usage():
5859
except KeyboardInterrupt:
5960
pass; do_exit = 1
6061

61-
print
62+
print()
6263
b["dist"].print_log2_hist("usecs")
6364
b["dist"].clear()
6465
if do_exit:

‎src/cc/frontends/p4/compiler/topoSorting.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
# -*- coding: utf-8 -*-
2222

23+
from __future__ import print_function
2324

2425
class Node(object):
2526
def __init__(self, n):
@@ -55,7 +56,7 @@ def visit(node, topo_sorting, sequence=None):
5556
sequence += [str(node)]
5657
if node._behavioral_topo_sorting_mark == 1:
5758
if sequence is not None:
58-
print "cycle", sequence
59+
print("cycle", sequence)
5960
return False
6061
if node._behavioral_topo_sorting_mark != 2:
6162
node._behavioral_topo_sorting_mark = 1

‎src/cc/frontends/p4/test/testP4toEbpf.py‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
# Runs the compiler on all files in the 'testprograms' folder
77
# Writes outputs in the 'testoutputs' folder
88

9+
from __future__ import print_function
910
from bcc import BPF
1011
import os, sys
1112
sys.path.append("../compiler") # To get hold of p4toEbpf
@@ -37,9 +38,9 @@ def main():
3738
errors = 0
3839

3940
if not is_root():
40-
print "Loading EBPF programs requires root privilege."
41-
print "Will only test compilation, not loading."
42-
print "(Run with sudo to test program loading.)"
41+
print("Loading EBPF programs requires root privilege.")
42+
print("Will only test compilation, not loading.")
43+
print("(Run with sudo to test program loading.)")
4344

4445
for f in files:
4546
path = os.path.join(testpath, f)
@@ -57,7 +58,7 @@ def main():
5758
result = p4toEbpf.process(args)
5859
if result.kind != "OK":
5960
errors += 1
60-
print path, result.error
61+
print(path, result.error)
6162
set_error(result.kind, path, result.error)
6263
else:
6364
# Try to load the compiled function
@@ -72,11 +73,11 @@ def main():
7273

7374
filesDone += 1
7475

75-
print "Compiled", filesDone, "files", errors, "errors"
76+
print("Compiled", filesDone, "files", errors, "errors")
7677
for key in sorted(filesFailed):
77-
print key, ":", len(filesFailed[key]), "programs"
78+
print(key, ":", len(filesFailed[key]), "programs")
7879
for v in filesFailed[key]:
79-
print "\t", v
80+
print("\t", v)
8081
exit(len(filesFailed) != 0)
8182

8283

0 commit comments

Comments
 (0)