473,287 Members | 1,463 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,287 software developers and data experts.

preserve history in the interactive python

Hi,

I am using python -i, and I find it hard typing/pasting the commands
from the previous interactive shell. Basically, is there anyway that I
can preserve the history in the shell?
I guess but not sure there should be something like ~/.pyrc for
configuring such but can someone please let me know what is the
effective environment variable to preserve the history?

Thanks,
Nikhil
Jun 27 '08 #1
3 1233
Nikhil wrote:
Hi,

I am using python -i, and I find it hard typing/pasting the commands
from the previous interactive shell. Basically, is there anyway that I
can preserve the history in the shell?
I guess but not sure there should be something like ~/.pyrc for
configuring such but can someone please let me know what is the
effective environment variable to preserve the history?

Thanks,
Nikhil
>>there should be something like ~/.pyrc
please read it as something in a file pointed by PYTHONSTARTUP
environment variable. I am mostly here interested in saving the python
shell's history automatically.

Nikhil
Jun 27 '08 #2
Nikhil wrote:
Hi,

I am using python -i, and I find it hard typing/pasting the commands
from the previous interactive shell. Basically, is there anyway that I
can preserve the history in the shell?
I guess but not sure there should be something like ~/.pyrc for
configuring such but can someone please let me know what is the
effective environment variable to preserve the history?

Thanks,
Nikhil
I figured it out. This below thing works fine for me.
BTW, I got it from http://docs.python.org/tut/node15.html. A little
search would not hurt ;-)
$ echo $PYTHONSTARTUP
/u/me/.pyrc
$ cat .pyrc
import sys
import atexit
import os
import readline
import rlcompleter

myprompt='$ '
myhistoryfile="/u/me/.pyhistory"

#set the prompt
sys.ps1=myprompt

#save the history
historyPath = os.path.expanduser(myhistoryfile)

def save_history(historyPath=historyPath):
import readline
readline.write_history_file(historyPath)

if os.path.exists(historyPath):
readline.read_history_file(historyPath)

atexit.register(save_history)
del os, atexit, readline, rlcompleter, save_history, historyPath
Jun 27 '08 #3
Nikhil <mn*****@gmail.comwrites:
Nikhil wrote:
>Hi,

I am using python -i, and I find it hard typing/pasting the commands
from the previous interactive shell. Basically, is there anyway that
I can preserve the history in the shell?
I guess but not sure there should be something like ~/.pyrc for
configuring such but can someone please let me know what is the
effective environment variable to preserve the history?

Thanks,
Nikhil
I figured it out. This below thing works fine for me.
BTW, I got it from http://docs.python.org/tut/node15.html. A little
search would not hurt ;-)
Or you could use IPython (http://ipython.scipy.org/), "an Enhanced
Python Shell".

--
Arnaud
Jun 27 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Christoph Becker-Freyseng | last post by:
Hello, is there a way to dump (and save) the command-history of the python interactive mode. Thanks, Christoph Becker-Freyseng
15
by: Ashot | last post by:
This is sort of both Python and Vim related (which is why I've posted to both newsgroups). Python related: ---------------------- I have been frustrated for quite some time with a lack of a...
6
by: ThomasC | last post by:
Hello, How to configure Python2.5's interactive interpreter to get command history ? I always got ^[[A and ^[[B . Thank you !! Thomas#
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
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...
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...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
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)...

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.