perl "-n" option in python?

David Ascher da at ski.org
Sun May 2 19:34:39 EDT 1999


> [Juergen Hoetzel]
> I switched from perl to python some months ago.
> One think i liked in perl was the "-n" option to assume a 'while 
> (<>) { ... } loop around the script. I used this option to do some
> quick jobs on the command line. For example:
>
> perl -n -e "/regex/ && print"
>
> So i was never forced to use awk/sed.
>
> Why isn't there something equivalent in python?

Look at fileinput (standard library module), and look at the pp.py script
in the Demo/ subdirectory in the *source* distribution of Python.  Not
quite the same, but gets you partway there.	

--david






More information about the Python-list mailing list