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 20:40:51
Message-Id: 20120917213841.59cb2349@karnak.local
In Reply to: Re: [gentoo-user] new machine : suddenly Python 3 appears by Philip Webb
1 On Mon, 17 Sep 2012 14:45:41 -0400, Philip Webb wrote about Re:
2 [gentoo-user] new machine : suddenly Python 3 appears:
3
4 > 120917 David W Noon wrote:
5 > > On Mon, 17 Sep 2012 13:14:27 -0400, Philip Webb wrote re Python
6 > > 2/3 :
7 > >> print ' ',eval(expression)
8 > > The above line uses obsolete syntax. Try using
9
10 Some interesting quoting there. Those 2 sentences were quite a few
11 paragraphs apart when I typed them and now they're on a single line.
12
13 > > #!/usr/bin/python2 -3
14 > > for your hash-bang line on all your old Python scripts.
15 >
16 > Well, thanks for the info -- which is what I suspected -- ,
17 > but just what is the correct Python3 syntax for that simple print
18 > line ?
19
20 print(' {0}'.format(eval(expression)))
21
22 Pretty, isn't it? ... :-)
23
24 Just be aware that the above is only for your original print
25 statement. There are a myriad of new formatting options that address
26 various other configurations of the old print statement and the above
27 does not cover anything like all of them. That's why I wrote that a
28 "big RTFM" is required to learn the new syntax.
29
30 > This is my only Python script, which I got from somewhere long
31 > forgotten, & I generally don't have a need to do Python programming.
32
33 In the Gentoo world, programming in Python is always helpful.
34
35 > While this subject is open, can anyone tell me
36 > how to get Python3 started from CLI automatically to load the math
37 > item ? -- ie to do 'from math import *' without my having to type it ?
38
39 You can't. It is program code and you have to code it yourself.
40
41 > That would make it possible to use 'python' instead of my script,
42 > which would then allow me to use variables, sometimes an advantage.
43
44 I would simply write a more flexible script, one that does exactly what
45 I need it to do.
46
47 If your Python variable named "expression" contains an arithmetic
48 expression, you might be able to get the shell to evaluate it for you,
49 thus eliminating the need for Python; just be aware that shells do not
50 normally do logarithms, trigonometry or other transcendental functions.
51 --
52 Regards,
53
54 Dave [RLU #314465]
55 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
56 dwnoon@××××××××.com (David W Noon)
57 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

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>