[BangPypers] 2-cent Tip: Load modules at Startup

steve steve at lonetwin.net
Fri Oct 23 09:11:55 CEST 2009

On 10/22/2009 07:41 PM, Noufal Ibrahim wrote:
> On Thu, Oct 22, 2009 at 6:43 PM, Amit Saha<lists.amitsaha at gmail.com>  wrote:
>>  Hello:
>>  I have been using CPython as a calculator, while I do all those number
>>  crunching in C. SO, 'import math' is a must.
>>  This is what I did:
>>  - Create a file: .pythonrc in my $HOME and place this line:
> There are other goodies you can put there as well. I used to have
> import readline
> readline.parse_and_bind("tab: complete")
> in there so that the default interpreter would get tab completion.

I also have this is my .pythonrc:

import os
import readline
histfile = os.path.join(os.environ["HOME"], ".pyhist")
except IOError:
import atexit
atexit.register(readline.write_history_file, histfile)
del os, histfile

This lets you save the history of every thing you type in your interpreter 
session much like the bash history functionality. This is immensely useful when 
I am trying out stuff on the prompt before creating a script.

Of course all this also comes built-in with the Ipython environment, but I never 
really got hooked on to that.

Anyways, besides the tip, I'd also like to point out to the 'atexit' module 
which the above tip uses. It is included in the stdlib and can prove to be quite 
useful at times. That one is good to know about.

- steve
random non tech spiel: http://lonetwin.blogspot.com/
tech randomness: http://lonehacks.blogspot.com/
what i'm stumbling into: http://lonetwin.stumbleupon.com/

More information about the BangPypers mailing list