Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > preserve history in the interactive python

Reply
Thread Tools

preserve history in the interactive python

 
 
Nikhil
Guest
Posts: n/a
 
      05-20-2008
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
 
Reply With Quote
 
 
 
 
Nikhil
Guest
Posts: n/a
 
      05-20-2008
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
 
Reply With Quote
 
 
 
 
Nikhil
Guest
Posts: n/a
 
      05-20-2008
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
 
Reply With Quote
 
Arnaud Delobelle
Guest
Posts: n/a
 
      05-20-2008
Nikhil <(E-Mail Removed)> writes:

> 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
 
Reply With Quote
 
Martin Marcher
Guest
Posts: n/a
 
      05-20-2008
Hi,

On Tue, May 20, 2008 at 8:19 PM, Nikhil <(E-Mail Removed)> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
The Python interactive interpreter has no command history ThomasC Python 6 02-26-2007 03:49 PM
IDLE history, Python IDE, and Interactive Python with Vim Ashot Python 22 02-08-2005 05:38 AM
dumping command-history in python interactive mode Christoph Becker-Freyseng Python 3 07-18-2003 01:47 PM
RE: dumping command-history in python interactive mode POYEN OP Olivier (DCL) Python 0 07-18-2003 08:31 AM
FileUtils - :preserve does not preserve mtime of directories on Windoze Grzegorz Chrupala Ruby 2 06-30-2003 07:38 AM



Advertisments