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

Amit Saha lists.amitsaha at gmail.com
Thu Oct 22 15:13:19 CEST 2009


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:

  <code>
    import math
</code>

- Now in your BASH, .bashrc or similar: export PYTHONSTARTUP= 
$HOME/.pythonrc

Everytime you start Python interactively, you should have the 'math' 
module already imported.

<code>

$ python
Python 2.6.4rc1 (r264rc1:75270, Oct 10 2009, 02:40:56)
[GCC 4.4.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
 >>> math.pi
3.1415926535897931

</code>

Hope this helps.


-Amit
-- 
Journal: http://amitksaha.wordpress.com
µ-blog: http://twitter.com/amitsaha
IRC: cornucopic on #scheme, #lisp, #math, #linux


More information about the BangPypers mailing list