".>>>" is a good idea! (OT, was: Re: do you master list comprehensions?)

Fernando Perez fperez528 at yahoo.com
Thu Dec 16 18:51:23 EST 2004


Kent Johnson wrote:

> Keith Dart wrote:
>> What I do is set Python's sys.ps1 variable to something else. I have a
>> module called "interactive" that I import implicitly by shell alias:
>> 
>> py='python -i -c '\''import interactive'\'
>> 
>> Which, among other things, sets the prompt to "Python> "
> 
> You can do the same thing using a PYTHONSTARTUP file - see
> http://docs.python.org/tut/node4.html#SECTION004240000000000000000
> 
> You can change the prompts with
> import sys
> sys.ps1 = ' >>> '
> sys.ps2 = ' ... '

<blatant plug>

You might want to look at ipython:

http://ipython.scipy.org,

which provides you automatically with these prompts:

In [1]: for i in range(2):
   ...:     print i,
   ...:
0 1

In [2]: 99*2
Out[2]: 198

In [3]: _2+1
Out[3]: 199

As a curiosity, ipython was actually born as a sys.ps1/2 hack, by assigning to
these objects whose __repr__ would give numbered prompts with results caching. 
These days it's a full-blown pure python interpreter, not a $PYTHONSTARTUP
customization anymore, but it's an interesting little historical curiosity. 
Especially if you start going very far with interactive customizations, you
might not want to rewrite all of ipython's 15K lines of code :)

</blatant plug>

Cheers,

f




More information about the Python-list mailing list