1 |
On Mon, 17 Sep 2012 17:17:47 -0400, Philip Webb wrote about Re: |
2 |
[gentoo-user] new machine : suddenly Python 3 appears: |
3 |
|
4 |
> 120917 Philip Webb wrote: |
5 |
> > 120917 David W Noon wrote: |
6 |
> >> print(' {0}'.format(eval(expression))) |
7 |
> |
8 |
> That works properly with Python2 in this machine ; |
9 |
> I'll check it with Python3 later in the new machine. |
10 |
|
11 |
That *is* Python 3 syntax. It is also accepted under recent releases |
12 |
of Python 2. |
13 |
|
14 |
> > 120917 Marc Joliet wrote: |
15 |
> >> print(' ',eval(expression)) |
16 |
> |
17 |
> That does the calculation, but the output is wrongly formatted : |
18 |
> |
19 |
> 514 bin> pycalc1 2+3 |
20 |
> (' ', 5) |
21 |
|
22 |
This is because Marc's code is syntactically invalid for Python 3. It |
23 |
is acceptable to Python 2, but does not do what you want; but it won't |
24 |
work at all under Python 3. |
25 |
|
26 |
It is clear that you have not taken my advice to use the -3 run-time |
27 |
option in your hash-bang line. At the risk of blowing my own trumpet, |
28 |
that was *extremely sound* advice; you should really take it. It would |
29 |
have revealed the problems with the above code during the Python |
30 |
interpreter's initial scan of the code. I'll repeat it: |
31 |
!#/usr/bin/python2 -3 |
32 |
This will perform a Python 3 syntax check, even under Python 2. It |
33 |
will identify any going-forward issues for your Python script(s). |
34 |
-- |
35 |
Regards, |
36 |
|
37 |
Dave [RLU #314465] |
38 |
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* |
39 |
dwnoon@××××××××.com (David W Noon) |
40 |
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* |