Mimick tac with python.

Chris Angelico rosuav at gmail.com
Fri Jan 29 23:56:17 EST 2016


On Sat, Jan 30, 2016 at 3:46 PM, Hongyi Zhao <hongyi.zhao at gmail.com> wrote:
> I can use the following methods for mimicking tac command bellow:
>
> awk '{a[NR]=$0} END {while (NR) print a[NR--]}' input_file
> perl -e 'print reverse<>' input_file
>
> Is it possible to do the same thing with python?

python -c 'import sys; print("".join(list(open(sys.argv[1]))[::-1]))' input_file

Python doesn't have a short-hand for grabbing the file named as an
argument, but it's easy enough to reverse stuff.

ChrisA



More information about the Python-list mailing list