473,320 Members | 1,951 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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 1670
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

50
by: Dan Perl | last post by:
There is something with initializing mutable class attributes that I am struggling with. I'll use an example to explain: class Father: attr1=None # this is OK attr2= # this is wrong...
6
by: Avi Berkovich | last post by:
Hello, I was unable to use popen2.popen4 to grab python.exe's (2.3) output, for starts, it doesn't show the version information at the beginning and won't return anything when writing to the...
5
by: Dave Opstad | last post by:
I'm hoping someone can point out where I'm going wrong here. Here's a snippet of a Python interactive session (2.3, if it makes a difference): -------------------------------------- >>> class...
20
by: Joe | last post by:
When you run "python -i scriptname.py" after the script completes you left at the interactive command prompt. Is there a way to have this occur from a running program? In other words can I...
2
by: Charles Krug | last post by:
List: I'm trying to us pylab to see what I'm doing with some DSP algorithms, in case my posts about convolution and ffts weren't giving it away. I've been using pylab's plot function, but I'm...
13
by: dmh2000 | last post by:
I am experimenting with the interactive interpreter environments of Python and Ruby and I ran into what seems to be a fundamental difference. However I may be doing something wrong in Python....
2
by: Adam Blinkinsop | last post by:
I'm writing a set of modules to monitor remote system services, and I'm having a problem running my test scripts. When I pass the scripts into python, like so: -- $ PYTHONPATH="${TARGET_DIR}"...
3
by: R. Bernstein | last post by:
The next release of pydb will have the ability to go into ipython from inside the debugger. Sort of like how in ruby-debug you can go into irb :-) For ipython, this can be done pretty simply;...
8
by: james.kirin39 | last post by:
Hi everyone, After having used Python on Linux for some time, I now have to do Python coding on Windows. I am big fan of the interactive Python shell to test, eg, regexps. Is there an...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.