Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #102278
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Mimick tac with python. |
| Date | 2016-01-30 15:56 +1100 |
| Message-ID | <mailman.112.1454130103.2338.python-list@python.org> (permalink) |
| References | <n8hf7c$lqe$1@aspen.stu.neva.ru> |
On Sat, Jan 30, 2016 at 3:46 PM, Hongyi Zhao <hongyi.zhao@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
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
Mimick tac with python. Hongyi Zhao <hongyi.zhao@gmail.com> - 2016-01-30 04:46 +0000
Re: Mimick tac with python. Random832 <random832@fastmail.com> - 2016-01-29 23:58 -0500
Re: Mimick tac with python. Christian Gollwitzer <auriocus@gmx.de> - 2016-01-30 07:03 +0100
Re: Mimick tac with python. Jussi Piitulainen <jussi.piitulainen@helsinki.fi> - 2016-01-30 09:56 +0200
Re: Mimick tac with python. Christian Gollwitzer <auriocus@gmx.de> - 2016-01-30 10:23 +0100
Re: Mimick tac with python. Peter Otten <__peter__@web.de> - 2016-01-30 09:21 +0100
Re: Mimick tac with python. Terry Reedy <tjreedy@udel.edu> - 2016-01-30 04:38 -0500
Re: Mimick tac with python. Hongyi Zhao <hongyi.zhao@gmail.com> - 2016-01-30 06:18 +0000
Re: Mimick tac with python. Chris Angelico <rosuav@gmail.com> - 2016-01-30 15:56 +1100
csiph-web