Re: [PATCH] perf scripts python: Add Python 3 support to mem-phys-addr.py

From: seeteena
Date: Thu Jan 17 2019 - 04:48:30 EST


I have added


On 01/16/2019 10:02 PM, Jonathan Corbet wrote:
On Wed, 16 Jan 2019 21:53:36 +0530
Seeteena Thoufeek <s1seetee@xxxxxxxxxxxxxxxxxx> wrote:

Support both Python 2 and Python 3 in mem-phys-addr.py. ``print`` is now a
function rather than a statement. This should have no functional change.

Fix lambda syntax error.
So, I just picked one of these at random....

Signed-off-by: Seeteena Thoufeek <s1seetee@xxxxxxxxxxxxxxxxxx>
Reviewed-by: Ravi Bangoria <ravi.bangoria@xxxxxxxxxxxxx>
---
tools/perf/scripts/python/mem-phys-addr.py | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/tools/perf/scripts/python/mem-phys-addr.py b/tools/perf/scripts/python/mem-phys-addr.py
index ebee2c5..52fe9bd 100644
--- a/tools/perf/scripts/python/mem-phys-addr.py
+++ b/tools/perf/scripts/python/mem-phys-addr.py
@@ -38,14 +38,14 @@ def parse_iomem():
pmem.append(long(m[1], 16))
def print_memory_type():
- print "Event: %s" % (event_name)
- print "%-40s %10s %10s\n" % ("Memory type", "count", "percentage"),
- print "%-40s %10s %10s\n" % ("----------------------------------------", \
- "-----------", "-----------"),
+ print("Event: %s" % (event_name))
+ print("%-40s %10s %10s\n" % ("Memory type", "count", "percentage")),
+ print("%-40s %10s %10s\n" % ("----------------------------------------", \
+ "-----------", "-----------")),
You have not added "from __future__ import print_function", so you're
relying on a Python 2 parsing oddity to make this work. If anybody ever
adds a second parameter, things will break. I think that if you really
want to support both versions (which seems like the right goal) you should
add the import and do it properly.

Thanks,

jon


Thanks Jonathan. I have added "from __future__ import print_function" for all the scripts.