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
Nikhil
$ 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
> 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
On Tue, May 20, 2008 at 8:19 PM, Nikhil <mni...@gmail.com> wrote:
> Nikhil wrote:
>> the previous interactive shell. Basically, is there anyway that I can
>> preserve the history in the shell?
>
> 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
Didn't even think of that, now that I have it: I love you - it's great.
To the one that implemented this: If you ever come to vienna, drop me
a note I'll get you a $FAVORITE_DRINK_HERE
/martin
--
http://www.xing.com/profile/Martin_Marcher
You are not free to read this message,
by doing so, you have violated my licence
and are required to urinate publicly. Thank you.