lkml.org 
[lkml]   [2019]   [Jan]   [21]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH v3] perf scripts python: Add Python 3 support to export-to-sqlite.py
From
Date
On 1/21/19 2:39 AM, Seeteena Thoufeek wrote:
> Support both Python 2 and Python 3 in export-to-sqlite.py. ``print`` is
> now a function rather than a statement. This should have no functional
> change.
>
> Also, handles the conversion of "print >> sys.stderr".
>
> Signed-off-by: Seeteena Thoufeek <s1seetee@linux.vnet.ibm.com>
> Reviewed-by: Ravi Bangoria <ravi.bangoria@linux.ibm.com>
> ---
> tools/perf/scripts/python/export-to-sqlite.py | 19 ++++++++++---------
> 1 file changed, 10 insertions(+), 9 deletions(-)
>
> diff --git a/tools/perf/scripts/python/export-to-sqlite.py b/tools/perf/scripts/python/export-to-sqlite.py
> index 245caf2..95bfcb2 100644
> --- a/tools/perf/scripts/python/export-to-sqlite.py
> +++ b/tools/perf/scripts/python/export-to-sqlite.py
> @@ -9,6 +9,7 @@
> # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
> # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
> # more details.
> +from __future__ import print_function

So is the script failing for you without the above

As I said in previous reviews you should not need this unless you are using features of the latest print function (end, sep etc). You will need this import in the other scripts (once you fix the numerous errors regarding the trailing comma usage) as some need to concatenate output onto one line but I don't think you need it here.

tony


$ python2 --version
Python 2.7.15
$ python3 --version
Python 3.6.5

$ a='print("abcd") ; print("defg")'
$ echo $a | python2
abcd
defg
$ echo $a | python3
abcd
defg

$ b='print("abcd", end="") ; print("defg")'
$ echo $b | python2
File "<stdin>", line 1
print("abcd", end="") ; print("defg")
^
SyntaxError: invalid syntax
$ echo $b | python3
abcddefg

$ c='from __future__ import print_function ; print("abcd", end="") ; print("defg")'
$ echo $c | python2
abcddefg
$ echo $c | python3
abcddefg

\
 
 \ /
  Last update: 2019-01-21 18:39    [W:0.037 / U:0.396 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site