PyOne is NOT RECOMMENDED for beginners. One-liner scripts are neither easy to debug nor easy to reuse. This is for those who are Python lovers, but still captives of Perl one-liner.
(Updated, May 13/2004: I've noticed this appeared at Daily Python url... But believe me, after trying this, I found using indentation with vi is still way easier than this!)
pyone [-d] [-i modules] [-f modules] script args ...
-d
-i modules
import modules' at the beginning of the script.
-f modules
from modules import *' for each module.
;
A
B
C
{ ... }
A:
B
C
EL{ ... }
The following variables are available inside the loop.
L: current line number.
S: current raw text, including "\n".
s: stripped text line.
F[]: splited fields with DELIM.
I[]: integer value obtained from each field if any.
Precisely, it inserts the folloing code:
L = -1
while 1:
S = getnextline(args)
if not S: break
L = L + 1
s = string.strip(S)
F = string.split(s, DELIM)
I = map(toint, F)
(... your code here ...)
DELIM
args[]
$ pyone 2+3*5.6
$ pyone -f cdb 'd=init("hoge.cdb");EL{if d.get(F[0]): print s}' testfiles
$ wget -q -O- http://slashdot.org/ | \
pyone -f sgmllib 't=[""];class p(SGMLParser){def handle_data(s,x){global t;t[-1]+=x;} \
def start_td(s,x){t.append("")} def end_td(s){print t[-1];del(t[-1])}} \
x=p(); EL{x.feed(s)}'
Yusuke Shinyama (yusuke at cs . nyu . edu)