468,110 Members | 1,793 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,110 developers. It's quick & easy.

Initializing interactive Python

Hi all,
is it possible to enter an interactive session and automatically
do some initialization?
I explain better:
I want that when I start interactive Python on a console (I use Linux)
two command lines be executed automatically:

Python 2.3.4 (#2, Aug 19 2004, 15:49:40)
[GCC 3.4.1 (Mandrakelinux (Alpha 3.4.1-3mdk)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
import sys
x01=x02=0


I would like not to have to write anything at the prompt >>> to run
the two commands, but be ready to start the interactive session.
Bye.

Jul 24 '05 #1
3 1513
qw******@yahoo.it a écrit :
Hi all,
is it possible to enter an interactive session and automatically
do some initialization?
I explain better:
I want that when I start interactive Python on a console (I use Linux)
two command lines be executed automatically:
bruno@bibi bruno $ python -h
(snip)
Other environment variables:
PYTHONSTARTUP: file executed on interactive startup (no default)
(snip)
Python 2.3.4 (#2, Aug 19 2004, 15:49:40)
[GCC 3.4.1 (Mandrakelinux (Alpha 3.4.1-3mdk)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
import sys
x01=x02=0

I would like not to have to write anything at the prompt >>> to run
the two commands, but be ready to start the interactive session.
Bye.


bruno@bibi bruno $ cat ~/.pythonrc.py
import sys
x01=x02=0
bruno@bibi bruno $ export PYTHONSTARTUP=~/.pythonrc.py
bruno@bibi bruno $ python
Python 2.4.1 (#1, Jul 23 2005, 00:37:37)
[GCC 3.3.4 20040623 (Gentoo Linux 3.3.4-r1, ssp-3.3.2-2, pie-8.7.6)] on
linux2
Type "help", "copyright", "credits" or "license" for more information.
sys <module 'sys' (built-in)> x01 0 x02 0


Easy as pie !-)

HTH
Bruno

Jul 24 '05 #2
On Sun, Jul 24, 2005 at 03:26:06AM -0700, qw******@yahoo.it wrote:
Hi all,
is it possible to enter an interactive session and automatically
do some initialization?


set the enviroment variable PYTHONSTARTUP to point to a startup.py of
your own, where you put all your initializations..

HTH

--
Thanos Tsouanas .: My Music: http://www.thanostsouanas.com/
http://thanos.sians.org/ .: Sians Music: http://www.sians.org/
Jul 24 '05 #3
Hi Bruno,
thank you..."Easy as pie !-)"
Bye.

Jul 24 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

50 posts views Thread by Dan Perl | last post: by
6 posts views Thread by Avi Berkovich | last post: by
5 posts views Thread by Dave Opstad | last post: by
20 posts views Thread by Joe | last post: by
2 posts views Thread by Charles Krug | last post: by
2 posts views Thread by Adam Blinkinsop | last post: by
3 posts views Thread by R. Bernstein | last post: by
8 posts views Thread by james.kirin39 | last post: by
1 post views Thread by Solo | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.