IIRC I created the fileinput module to help with this, but I don't know how much use it finds.
On Thu, Nov 5, 2020 at 10:05 AM Hans Ginzel email@example.com wrote:
Is there a reason, why not to make python useful for practical one liners to replace perl and awk? There is page Powerful Python One-Liners, https://wiki.python.org/moin/Powerful%20Python%20One-Liners. But almost none of them handles files, behaves like unix filter or is ugly – must import modules, etc.
It seems that the command line options like -a, -n, -p, -F are still free. :-) https://docs.python.org/3/using/cmdline.html
E.g. -n would be almost equivalent to
import sys,os,re from fileinput import * for line in input(): <-c code comes here> close()
-p will print(line) as last command of the for cycle.
Why to learn Perl/awk/datamash/mlr/…, for “one line like” tasks?
Thank you in advance Hans
https://stackoverflow.com/questions/1589994/how-do-i-write-a-unix-filter-in-... Why not to have an elegant (one line) answer in python for questions like this?
https://stackoverflow.com/questions/40708370/drop-duplicates-and-keep-first-... _______________________________________________ Python-ideas mailing list -- firstname.lastname@example.org To unsubscribe send an email to email@example.com https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://firstname.lastname@example.org/message/IT5MXI... Code of Conduct: http://python.org/psf/codeofconduct/