Writing one-liners in Python (was: Re: [Tutor] help mee)

alan.gauld@bt.com alan.gauld@bt.com
Fri, 3 May 2002 16:07:54 +0100


> >       As a result, I don't know how one would convert to a
> >       one-liner, say, something along the lines of the following
> >       code:
> Also there is a bit of "use the right tool for the right 
> job".  python is not quick and dirty.  I usually use awk/sed 

I tend to agree with this but there is one other solution 
for 'non trivial' one liners that I'm surprised nobody 
has mentioned yet:

The python prompt.

Many things I'd do in Perl as a 'one liner' I do in Python 
by starting up the interactive prompt and typing the script 
one line at a time. It's a throwaway program like a one liner 
but more powerful too.

I know Perl has a kind of interactive mode but it takes a 
whole script and compiles it and runs it after an EOF. Pythons 
real interpreter mode is more suitable for the one liner 
type programs IMHO.

Alan G.