Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!txtfeed1.tudelft.nl!tudelft.nl!txtfeed2.tudelft.nl!amsnews11.chello.com!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'startup': 0.04; 'sys': 0.05; 'importerror:': 0.07; 'tab': 0.07; 'typed': 0.07; 'python': 0.08; '=====': 0.09; 'ioerror:': 0.09; 'sys,': 0.09; 'read.': 0.10; 'subject:python': 0.11; 'library': 0.14; '16,': 0.15; 'cc:addr:python-list': 0.15; '[it': 0.16; 'atexit': 0.16; 'complete")': 0.16; 'finney': 0.16; 'history.': 0.16; 'subject: \n ': 0.16; 'subject:between': 0.16; 'wed,': 0.17; 'wrote:': 0.18; 'cc:no real name:2**0': 0.21; 'systems.': 0.23; 'skip:\xa0 40': 0.23; 'header:In-Reply-To:1': 0.23; 'command': 0.24; 'shell': 0.24; 'cc:2**0': 0.25; 'code': 0.25; 'writes:': 0.25; 'fine': 0.26; 'windows': 0.26; 'thanks.': 0.26; "i'm": 0.26; 'developing': 0.26; 'import': 0.28; 'cc:addr:python.org': 0.29; 'message-id:@mail.gmail.com': 0.29; 'received:209.85.214': 0.30; 'os,': 0.30; 'received:mail-bw0-f46.google.com': 0.30; 'url:library': 0.30; 'nov': 0.31; 'pm,': 0.31; 'skip:\xa0 30': 0.32; 'yet': 0.32; "can't": 0.32; 'there': 0.33; 'operating': 0.33; 'file.': 0.34; '8bit%:3': 0.34; 'try:': 0.34; 'url:python': 0.35; 'file': 0.36; 'skip:" 10': 0.36; 'another': 0.36; 'but': 0.37; 'using': 0.37; 'linked': 0.38; 'received:google.com': 0.38; 'received:209.85': 0.38; 'url:org': 0.38; 'url:docs': 0.38; 'except': 0.39; 'why': 0.39; 'subject:: ': 0.39; 'history': 0.40; 'received:209': 0.40; 'user': 0.40; 'managing': 0.60; 'your': 0.61; '2011': 0.62; 'skip:$ 10': 0.63; 'skip:o 30': 0.63; 'subject:will': 0.64; 'enable': 0.65; 'completion': 0.80; 'subject:commands': 0.84; 'subject:history': 0.84; 'url:lib': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=Z0+rXihdiJywwNy/3oDw1+lDS7sqKqEaNkUpUqXfeRg=; b=upYC/2FtjC1CdJDRt8J20YEO9voiSwIGL9S7UBqgIc/RK1GbvwiJYlPwAmUC+84H4y O3D94s2D2omMzAuYwZ0k6JSoGurl+MlhmpWCQNL+FCf51r9YZSBm/kUAeldrlT+PbfwC OtP32JrgaC4Lm4nt+SnFGqkD3r+yWSWKaORjM= MIME-Version: 1.0 In-Reply-To: <8762ijlqpt.fsf@benfinney.id.au> References: <4737007e-029d-4ecb-9315-f3ceb4bb06ed@t16g2000vba.googlegroups.com> <8762ijlqpt.fsf@benfinney.id.au> Date: Wed, 16 Nov 2011 18:46:30 -0500 Subject: Re: python shell that saves history of typed in commands that will persist between reboots From: David Robinow To: Ben Finney Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 59 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1321487193 news.xs4all.nl 6927 [2001:888:2000:d::a6]:37122 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:15793 On Wed, Nov 16, 2011 at 4:09 PM, Ben Finney wr= ote: > 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 > 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: > > =3D=3D=3D=3D=3D > # $HOME/.pythonrc > # User configuration for interactive Python shell. > > import sys > import os > import os.path > import atexit > > # Tab completion with readline. > # Cribbed from . > try: > =A0 =A0import readline > except ImportError: > =A0 =A0sys.stderr.write("Module readline not available.\n") > else: > =A0 =A0import rlcompleter > > =A0 =A0# Enable tab completion. > =A0 =A0readline.parse_and_bind("tab: complete") > > =A0 =A0# Persistent command history. > =A0 =A0histfile =3D os.path.join(os.environ["HOME"], ".python_history") > =A0 =A0try: > =A0 =A0 =A0 =A0readline.read_history_file(histfile) > =A0 =A0except IOError: > =A0 =A0 =A0 =A0# Existing history file can't be read. > =A0 =A0 =A0 =A0pass > =A0 =A0atexit.register(readline.write_history_file, histfile) > > =A0 =A0del histfile > > del sys, os, atexit > > =3D=3D=3D=3D=3D > > Reading the documentation, I see that the =91readline=92 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 o= n Windows. Thanks. [It is necessary to properly set PYTHONSTARTUP]