Python as a default shell, replacement of bash, sh, cmd ?

Steven D'Aprano steve+comp.lang.python at
Wed Feb 22 23:15:55 CET 2012

On Wed, 22 Feb 2012 15:31:10 +0000, Grant Edwards wrote:

> On 2012-02-22, Kyle T. Jones <onexpadREMOVE at>
> wrote:
>> On 2/19/12 2:16 AM, SherjilOzair wrote:
>>> Well, if not modify python itself, I was thinking of making another
>>> shell, which borrows a lot from python, something like merging bash
>>> and python. such that I can do `cd ~/Desktop/dev` and `for i in
>>> open('file.txt'): print i` at the some shell. This I think would be
>>> VERY useful.
>> That's an awful lot of key mashing just to replace 'cat file.txt'
> No kidding.  And how much python would it take to do "less file.txt"?

A lot less than the amount of C it takes to do "less file.txt".

I trust you don't imagine that a Python shell would require the user to 
re-implement "less" using nothing but built-ins each time they needed it. 
There would be a pre-made "less" replacement (which may even be a wrapper 
around the system "less") never more than one import away. You can 
already do something very close to this right now:

from pydoc import pager

How much effort would it take to turn pydoc.pager into a full replacement 
for "less"? I don't know, but it would only need to be done ONCE.

This is not a theoretical argument. IPython already does this. It not 
only gives you full access to all your shell commands, plus more, but it 
let's you use something very close to shell syntax to do it.

The advantage of a Python shell like IPython is not for trivial shell 
commands like "less file.txt". I can think of at least four reasons why 
you might consider a Python shell would be awesome:

"I know Python, and I don't know bash. What do I care if it takes five 
lines to perform a task in Python, vs one line in bash, if it would take 
me half an hour of reading man pages and seven attempts to get the bash 
version right?"

"I'm fed up to the back teeth of the shell's cryptic syntax, magic global 
variables and especially its arcane string quoting rules."

"I'm sick and tired of having to parse human-readable presentation text 
to get the answers I want. I want an environment where the tools don't 
mix content and presentation by default."

"My OS has a shell which sucks and blows at the same time. I want 
something better."

So basically, there exists a niche for Python as a shell, and thanks to 
the time machine, there already exists a powerful Python shell ready to 
fill that niche.


More information about the Python-list mailing list