[PATCH evemu 02/11] py: Replace print statement with function call

Daniel Martin consume.noise at gmail.com
Sat Jan 4 04:41:57 PST 2014


On Sat, Jan 04, 2014 at 02:14:38PM +1000, Peter Hutterer wrote:
> On 4/01/2014 01:27 , Daniel Martin wrote:
> >On Fri, Jan 03, 2014 at 10:24:37AM +1000, Peter Hutterer wrote:
> >>On Thu, Jan 02, 2014 at 10:47:52PM +0100, Daniel Martin wrote:
> >>>As of Python 3 the print statement has been replaced by a function and
> >>>Python 3 has no backward compatibility for it (like Python 2.7), causing
> >>>syntax errors on such statements.
> >>>
> >>>Replace all print statements with the function call and bump the Python
> >>>package requirement to version 2.7. Because, these changes make the
> >>>scripts incompatible with Python 2.6.
> >>>
> >>>Signed-off-by: Daniel Martin <consume.noise at gmail.com>
> >>>---
> >>>  configure.ac                    |  2 +-
> >>>  src/convert-old-dumps-to-1.1.py | 18 ++++----
> >>>  src/make-event-names.py         | 94 ++++++++++++++++++++---------------------
> >>>  3 files changed, 57 insertions(+), 57 deletions(-)
> >>>
> >>>diff --git a/configure.ac b/configure.ac
> >>>index d9f434f..0bd51a9 100644
> >>>--- a/configure.ac
> >>>+++ b/configure.ac
> >>>@@ -31,7 +31,7 @@ AC_PROG_LIBTOOL
> >>>  AC_PROG_CC
> >>>  AC_PROG_CXX
> >>>  AC_PROG_INSTALL
> >>>-AM_PATH_PYTHON([2.6])
> >>>+AM_PATH_PYTHON([2.7])
> >>
> >>I'd rather keep the min requirement on 2.6 for RHEL6 compatibility and use
> >>from __future__ import print_function.
> >
> >Just installed 2.6(.8) to test this and it works even without the
> >__future__ import. print is already a function:
> 
> the from __future__ import statement removes print as a language statement.
> so it simply prevents us from accidentally introducing a python3-invalid
> print statement.
> 
> >
> >     >>> help("__builtin__.print")
> >     Help on built-in function print in __builtin__:
> >
> >     __builtin__.print = print(...)
> >         print(value, ..., sep=' ', end='\n', file=sys.stdout)
> >     ---8<---
> >
> >I've digged through the NEWS file, but couldn't find any hint since when
> >this is the case. Anyone else knows some details?
> 
> found it: http://docs.python.org/2/library/functions.html#print says
> available since 2.6.
> 
> btw, not sure how you did the conversion but the 2to3 script may uncover a
> few more things.

I've made it the classic trial and error way. But, I've tested 2to3 now.
It would remove the "from __future__ ..." and add a list() around
dictionaries, which looks odd:
    list(some_dict.items())
No other changes pop up.


More information about the Input-tools mailing list