convert script awk in python

Pankaj Jangid pankaj at codeisgreat.org
Fri Mar 26 02:21:36 EDT 2021


Christian Gollwitzer <auriocus at gmx.de> writes:

> The closest equivalent I can come up with in Python is this:
>
> ==============================
> import sys
>
> s=0
> for line in sys.stdin:
>     try:
>         s += float(line.split()[1])
>     except:
>         pass
> print(s)
> ===================================
>
>
> I don't want to cram this into a python -c " "  line, if it even is
> possible; how do you handle indentation levels and loops??
>

I agree. Perhaps we need a ‘awk’ module/package. I see that there is one
in PyPI but that was last updated in 2016.

-- 
Regards,
Pankaj Jangid



More information about the Python-list mailing list