Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > python shell that saves history of typed in commands that willpersist between reboots

Reply
Thread Tools

python shell that saves history of typed in commands that willpersist between reboots

 
 
goldtech
Guest
Posts: n/a
 
      11-16-2011
Hi,

Using Windows. Is there a python shell that has a history of typed in
commands?

I don't need output of commands just what I typed it. I need it to
save between sessions - something that no shell seems to do. If I
reboot there will still be a command history somewhere.

Like bash history in Linux.

Thanks
 
Reply With Quote
 
 
 
 
sword
Guest
Posts: n/a
 
      11-16-2011
Maybe you're looking for ipython? History, tab-complete, sort of
things in it.

goldtech wrote:
> Hi,
>
> Using Windows. Is there a python shell that has a history of typed in
> commands?
>
> I don't need output of commands just what I typed it. I need it to
> save between sessions - something that no shell seems to do. If I
> reboot there will still be a command history somewhere.
>
> Like bash history in Linux.
>
> Thanks

 
Reply With Quote
 
 
 
 
Tim Golden
Guest
Posts: n/a
 
      11-16-2011
On 16/11/2011 03:38, goldtech wrote:
> Hi,
>
> Using Windows. Is there a python shell that has a history of typed in
> commands?


Have a look at DreamPie:

http://dreampie.sourceforge.net/

TJG
 
Reply With Quote
 
David Robinow
Guest
Posts: n/a
 
      11-16-2011
On Wed, Nov 16, 2011 at 4:09 PM, Ben Finney <ben+> wrote:
> goldtech <> writes:
>
>> Using Windows. Is there a python shell that has a history of typed in
>> commands?

>
> I don't know about MS Windows, but the Python interactive shell can be
> linked with the GNU Readline library for managing its command line
> <URL:http://docs.python.org/library/readline.html> including editing
> features, tab completion, history management, and a persistent history
> file.
>
> You can then use that functionality in your Python interactive startup
> file. Here's mine:
>
> =====
> # $HOME/.pythonrc
> # User configuration for interactive Python shell.
>
> import sys
> import os
> import os.path
> import atexit
>
> # Tab completion with readline.
> # Cribbed from <URL:http://docs.python.org/lib/module-rlcompleter.html>.
> try:
> * *import readline
> except ImportError:
> * *sys.stderr.write("Module readline not available.\n")
> else:
> * *import rlcompleter
>
> * *# Enable tab completion.
> * *readline.parse_and_bind("tab: complete")
>
> * *# Persistent command history.
> * *histfile = os.path.join(os.environ["HOME"], ".python_history")
> * *try:
> * * * *readline.read_history_file(histfile)
> * *except IOError:
> * * * *# Existing history file can't be read.
> * * * *pass
> * *atexit.register(readline.write_history_file, histfile)
>
> * *del histfile
>
> del sys, os, atexit
>
> =====
>
> Reading the documentation, I see that the ‘readline’ library is only
> linked with Python on Unix-alike operating systems. Yet another reason
> why MS Windows is not a good choice for developing software I guess.


I'm not sure what documentation you're reading, but your code works fine on
Windows. Thanks. [It is necessary to properly set PYTHONSTARTUP]
 
Reply With Quote
 
David Robinow
Guest
Posts: n/a
 
      11-17-2011
On Wed, Nov 16, 2011 at 6:59 PM, Ben Finney <ben+> wrote:
> David Robinow <> writes:
>
>> On Wed, Nov 16, 2011 at 4:09 PM, Ben Finney <ben+>wrote:
>> > I don't know about MS Windows, but the Python interactive shell can be
>> > linked with the GNU Readline library for managing its command line
>> > <URL:http://docs.python.org/library/readline.html>

> […]
>
>> > Reading the documentation, I see that the ‘readline’ library is only
>> > linked with Python on Unix-alike operating systems.

>
>> *I'm not sure what documentation you're reading

>
> The same documentation I linked to above. Immediately below the title,
> it specifies a limited set of platforms: “Platforms: Unix” limiting the
> availability of the described module.
>
>> but your code works fine on Windows. Thanks.

>
> I'm glad to know that. Perhaps you could investigate why, and suggest an
> update to the above documentation if it's wrong? The bug tracker at
> <URL:http://bugs.python.org/> would be the appropriate place for such a
> suggestion.


Upon further investigation, it turns out that I'm using pyreadline
from http://pypi.python.org/pypi/pyreadline. I'd forgotten I'd
installed it. No documentation fixes appear to be necessary.

"The pyreadline package is a python implementation of GNU readline
functionality it is based on the ctypes based UNC readline package by
Gary Bishop. It is not complete. It has been tested for use with
windows 2000 and windows xp."
It appears to work in Vista also, at least for the purposes
discussed in this thread.
 
Reply With Quote
 
alex23
Guest
Posts: n/a
 
      11-17-2011
On Nov 17, 7:09*am, Ben Finney <ben+pyt...@benfinney.id.au> wrote:
> You can then use that functionality in your Python interactive startup
> file. Here's mine:


Awesome, thank you for this. I use iPython where ever possible but
there are times where I just can't avoid the default shell and this
will help immensely.

Cheers!
 
Reply With Quote
 
Anssi Saari
Guest
Posts: n/a
 
      11-23-2011
goldtech <> writes:

> Using Windows. Is there a python shell that has a history of typed in
> commands?


Is there a shell that doesn't have history then? At least both the
vanilla shell and Idle both have basic history in Windows. IPython for
more fun.
 
Reply With Quote
 
Steven D'Aprano
Guest
Posts: n/a
 
      11-23-2011
On Wed, 23 Nov 2011 11:23:19 +0200, Anssi Saari wrote:

> goldtech <> writes:
>
>> Using Windows. Is there a python shell that has a history of typed in
>> commands?

>
> Is there a shell that doesn't have history then? At least both the
> vanilla shell and Idle both have basic history in Windows. IPython for
> more fun.


The default interactive interpreter for Python doesn't have persistent
history, so if you exit the interpreter and restart it, your commands are
gone.


--
Steven
 
Reply With Quote
 
Tim Golden
Guest
Posts: n/a
 
      11-23-2011
On 23/11/2011 10:29, Steven D'Aprano wrote:
> On Wed, 23 Nov 2011 11:23:19 +0200, Anssi Saari wrote:
>
>> goldtech<> writes:
>>
>>> Using Windows. Is there a python shell that has a history of typed in
>>> commands?

>>
>> Is there a shell that doesn't have history then? At least both the
>> vanilla shell and Idle both have basic history in Windows. IPython for
>> more fun.

>
> The default interactive interpreter for Python doesn't have persistent
> history, so if you exit the interpreter and restart it, your commands are
> gone.


Not quite

The interpreter inherits the command shell's history function:
Open a cmd window and then a Python session. Do some stuff.

Ctrl-Z to exit to the surrounding cmd window.
Do some random cmd stuff: dir, cd, etc.

Start a second Python session. up-arrow etc. will bring back
the previous Python session's commands (and not the ones you
entered in the surrounding shell)

Obviously this only applies when an underlying cmd session
persists -- if you simply start Python from Start > Run
twice the command history will not persist between sessions.

TJG
 
Reply With Quote
 
Steven D'Aprano
Guest
Posts: n/a
 
      11-24-2011
On Wed, 23 Nov 2011 10:37:56 +0000, Tim Golden wrote:

> The interpreter inherits the command shell's history function: Open a
> cmd window and then a Python session. Do some stuff.
>
> Ctrl-Z to exit to the surrounding cmd window. Do some random cmd stuff:
> dir, cd, etc.
>
> Start a second Python session. up-arrow etc. will bring back the
> previous Python session's commands (and not the ones you entered in the
> surrounding shell)


Doesn't work for me, at least not with Python 2.5 and 2.6 on Linux.

I don't suppose you are running a site-specific command history script in
your startup.py file?


[steve@wow-wow ~]$ unset PYTHONSTARTUP
[steve@wow-wow ~]$ python
Python 2.5 (r25:51908, Nov 6 2007, 16:54:01)
[GCC 4.1.2 20070925 (Red Hat 4.1.2-27)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print 42

42
>>>

[1]+ Stopped python
[steve@wow-wow ~]$ python
Python 2.5 (r25:51908, Nov 6 2007, 16:54:01)
[GCC 4.1.2 20070925 (Red Hat 4.1.2-27)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>



You can't see it, but I'm hitting the up arrow on that last line, and
nothing is happening except my console is flashing


--
Steven
 
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
problem in running a basic code in python 3.3.0 that includes HTML file Satabdi Mukherjee Python 1 04-04-2013 07:48 PM
mix statically typed with dynamically typed Yingjie Lan Python 4 01-29-2010 08:50 AM
access built-in shell commands like 'history' or 'fc' bwv549 Ruby 9 08-11-2006 02:42 PM
Shell Commands in Python Code Sara Khalatbari Python 3 05-07-2005 05:21 PM
How can I add a row from a typed datatable to another instance of that typed datatable? Ersin Gençtürk ASP .Net 1 10-06-2004 01:11 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57