One line command line filter

Steven D'Aprano steve+comp.lang.python at
Tue Sep 6 01:29:00 CEST 2011

Jon Redgrave wrote:

> It seems unreasonably hard to write simple one-line unix command line
> filters in python:
> eg: ls | python -c "<something>  print x.upper()"

Python is neither bash nor Perl. It is not intended to compete in the "quick
and dirty one-liner commands" stakes.

However, you might like to consider ipython, which is intended as a complete
Python shell, not just an interactive interpreter.

> The best I've come up with is to use to add to
> __builtin__

If you're a system administrator who wants to replace bash one-liners at the
command line with Python one-liners, sure, why not?

If you build up a useful collection of sys admin tools or recipes, you might
like to consider sharing them. Perhaps if Python was used more by sys
admins, there might be less resistance to making it easier to compete with
bash one-liners.


More information about the Python-list mailing list