perl "-n" option in python?

Tim Peters tim_one at email.msn.com
Sun May 2 19:29:21 EDT 1999


[Juergen Hoetzel]
> I switched from perl to python some months ago.

And the world is a better place for it <wink>.

> 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?

There's something exactly equivalent:

python -c "import os;os.system('perl -ne \"/regex/ && print\"')"

That even works under Windows <wink>.

python's-the-right-tool-for-every-job-ly y'rs  - tim






More information about the Python-list mailing list