Gentoo Archives: gentoo-user

From: Marc Joliet <marcec@×××.de>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] new machine : suddenly Python 3 appears
Date: Thu, 20 Sep 2012 20:38:49
Message-Id: 20120920223545.4a21f9e0@marcec.hunte.us
In Reply to: Re: [gentoo-user] new machine : suddenly Python 3 appears by Willie WY Wong
1 Am Thu, 20 Sep 2012 13:38:45 +0200
2 schrieb Willie WY Wong <wongwwy@××××××××××.org>:
3
4 > On Wed, Sep 19, 2012 at 09:08:52AM +0200, Penguin Lover Marc Joliet squawked:
5 > > 2.) The full blown interactive solution: IPython. You can create a session and
6 > > configure which modules you want preloaded via startup scripts. This is
7 > > overkill for what you want, I think, but IPython is a much nicer interactive
8 > > Python interpreter than python itself. For instance, you can reuse previous
9 > > outputs, e.g. "Out[2]", to get the output from the third command you entered
10 > > (indexing starts at 0). Inputs can be similarly recalled by referencing
11 > > "In[i]".
12 >
13 > Yes, I recommend ipython too.
14 >
15 > > 3.) Put the "import" line in its own file and put it in the variable
16 > > PYTHONSTARTUP, e.g. "export PYTHONSTARTUP=/path/to/my/script.py". Python
17 > > executes it's contents before presenting the prompt, so you can put whatever
18 > > imports you want in that script. It's simple, and if the python interpreter is
19 > > enough for you, then I'd go with this.
20 > >
21 > > There are probably more possibilities, but this is what I can think of right
22 > > now.
23 >
24 > Unless you want to load the math module every single time you start
25 > Python, it is perhaps better to create an alias (say, python-calc)
26 > in bash (or shell of your choice) using the `-i' option of python
27 > like
28 > alias python-calc='python -i loadmath.py'
29 > or if you only need one single command
30 > alias python-calc='python -i -c "from math import *"'
31 > which will give you an interactive session with the math functions
32 > preloaded.
33
34 You are right, exporting PYTHONSTARTUP globally for something like this
35 in the bashrc would in this case be stupid, or at least wasteful. I like your
36 alias version better :) .
37
38 > Cheers,
39 >
40 > W
41
42 Greetings
43 --
44 Marc Joliet
45 --
46 "People who think they know everything really annoy those of us who know we
47 don't" - Bjarne Stroustrup

Attachments

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