On Mon, 17 Sep 2012 13:14:27 -0400, Philip Webb wrote about Re:
[gentoo-user] new machine : suddenly Python 3 appears:

> In case others might like to use it, the script is :
> 
>   #!/usr/bin/python2
>   from math import *
>   import sys
>   expression = sys.argv[1]
>   print '              ',eval(expression)

The above line uses obsolete syntax.  A big RTFM is required to get the
new syntax, as print is no longer a statement, but a subroutine (or
"void function" in C-speak).

> Its help is via 'pydoc math'.  Expressions need quotes if they have
> brackets.
> 
> It was failing with a syntax error in the print line,
> when the 1st line read  #!/usr/bin/python ,
> so I have to assume (1) that Python3 has been set as default
> -- No ! I didn't do it ! -- & (2) its syntax for printing has changed.

The latter -- and perhaps the former too, but that is irrelevant from
a going-forward point of view.

In fact, print changed a few years back, but Python 2,x tolerates the
old syntax unless you specify the -3 run-time option.  This option was
also recommended a few years back, so that syntax that will be flagged
by Python 3.x can be detected early (i.e. a few years back).  So, try
using
   #!/usr/bin/python2 -3
for your hash-bang line on all your old Python scripts.
-- 
Regards,

Dave  [RLU #314465]
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
dwn...@ntlworld.com (David W Noon)
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

Attachment: signature.asc
Description: PGP signature

Reply via email to