Gentoo Archives: gentoo-user

From: David W Noon <dwnoon@××××××××.com>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] new machine : suddenly Python 3 appears
Date: Mon, 17 Sep 2012 18:13:09
Message-Id: 20120917190846.4f4fd1c5@karnak.local
In Reply to: Re: [gentoo-user] new machine : suddenly Python 3 appears by Philip Webb
1 On Mon, 17 Sep 2012 13:14:27 -0400, Philip Webb wrote about Re:
2 [gentoo-user] new machine : suddenly Python 3 appears:
3
4 > In case others might like to use it, the script is :
5 >
6 > #!/usr/bin/python2
7 > from math import *
8 > import sys
9 > expression = sys.argv[1]
10 > print ' ',eval(expression)
11
12 The above line uses obsolete syntax. A big RTFM is required to get the
13 new syntax, as print is no longer a statement, but a subroutine (or
14 "void function" in C-speak).
15
16 > Its help is via 'pydoc math'. Expressions need quotes if they have
17 > brackets.
18 >
19 > It was failing with a syntax error in the print line,
20 > when the 1st line read #!/usr/bin/python ,
21 > so I have to assume (1) that Python3 has been set as default
22 > -- No ! I didn't do it ! -- & (2) its syntax for printing has changed.
23
24 The latter -- and perhaps the former too, but that is irrelevant from
25 a going-forward point of view.
26
27 In fact, print changed a few years back, but Python 2,x tolerates the
28 old syntax unless you specify the -3 run-time option. This option was
29 also recommended a few years back, so that syntax that will be flagged
30 by Python 3.x can be detected early (i.e. a few years back). So, try
31 using
32 #!/usr/bin/python2 -3
33 for your hash-bang line on all your old Python scripts.
34 --
35 Regards,
36
37 Dave [RLU #314465]
38 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
39 dwnoon@××××××××.com (David W Noon)
40 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

Attachments

File name MIME type
signature.asc application/pgp-signature

Replies

Subject Author
Re: [gentoo-user] new machine : suddenly Python 3 appears Philip Webb <purslow@××××××××.net>