Gentoo Archives: gentoo-user

From: Philip Webb <purslow@××××××××.net>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] new machine : suddenly Python 3 appears
Date: Mon, 17 Sep 2012 21:11:29
Message-Id: 20120917210838.GD2892@ca.inter.net
In Reply to: Re: [gentoo-user] new machine : suddenly Python 3 appears by David W Noon
1 120917 David W Noon wrote:
2 > On Mon, 17 Sep 2012 14:45:41 -0400, Philip Webb asked about
3 >> print ' ',eval(expression)
4 >> whose syntax is obsolete in Python3.
5 > print(' {0}'.format(eval(expression)))
6 > be aware that the above is only for your original print statement.
7 > There are a myriad of new formatting options that address
8 > various other configurations of the old print statement
9 > and the above does not cover anything like all of them.
10
11 Thanks : someone else suggested a different format below.
12 It doesn't matter today, but perhaps Python2 will disappear sometime.
13
14 >> how to get Python3 started from CLI automatically to load the math
15 >> item ? -- ie to do 'from math import *' without my having to type it ?
16 > You can't. It is program code and you have to code it yourself.
17 > If your Python variable "expression" contains an arithmetic expression,
18 > you might be able to get the shell to evaluate it for you,
19 > but shells do not normally do logs, trig or other transcendental functions.
20
21 Yes, that's why I use my script, which does all the everyday jobs.
22
23 120917 Marc Joliet wrote:
24 > print ' ',eval(expression)
25 > becomes
26 > print(' ',eval(expression))
27
28 Thanks for that version too (smile).
29
30 The one limitation of the script is that it doesn't allow variables ;
31 you can easily recall previous lines via Bash & mouseover+drop bits,
32 but AFAIK there's no way to assign values to variables.
33 With Python running as interpreter, I would get much more capability,
34 but I would need to enter the special line to load the math functions :
35 is it possible to do it with some capitalised variable in .bashrc ,
36 which might list parameters telling Python3 what to load when it starts ?
37 one of the 'man' files seems to refer to something like that, but briefly.
38
39 --
40 ========================,,============================================
41 SUPPORT ___________//___, Philip Webb
42 ELECTRIC /] [] [] [] [] []| Cities Centre, University of Toronto
43 TRANSIT `-O----------O---' purslowatchassdotutorontodotca

Replies

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