Hello,

On Thu, 5 Nov 2020 18:46:53 +0100
Hans Ginzel <h...@matfyz.cz> 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

Thankfully, command-line option "-m" is there for ages. And you're
looking for

python3 -m <my_favorite_DSL> <any_arguments>

Where <my_favorite_DSL> was put on https://pypi.org/ by you or
similarly-minded people, and installed with:

pip3 install --user <my_favorite_DSL>

before running the previous command (needs to be done only once).

> 
> Why not use them almost the same way as in Perl?
> https://perldoc.perl.org/perlrun#-n
> https://perldoc.perl.org/perlrun#-p
> https://perldoc.perl.org/perlrun#-a
> https://perldoc.perl.org/perlrun#-Fpattern
> 
> 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
> 
> PS:
> https://blogs.oracle.com/linux/the-top-10-tricks-of-perl-one-liners-v2
> https://gist.github.com/joyrexus/7328094
> https://stackoverflow.com/questions/1589994/how-do-i-write-a-unix-filter-in-python
> 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-in-a-csv-file-in-unix

[]

-- 
Best regards,
 Paul                          mailto:pmis...@gmail.com
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/QEI2YZNMBEWOK4EL2WSSAABGXTEZKK73/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to