Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #102277

Re: Mimick tac with python.

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Random832 <random832@fastmail.com>
Newsgroups comp.lang.python
Subject Re: Mimick tac with python.
Date Fri, 29 Jan 2016 23:58:38 -0500
Lines 14
Message-ID <mailman.111.1454129921.2338.python-list@python.org> (permalink)
References <n8hf7c$lqe$1@aspen.stu.neva.ru>
Mime-Version 1.0
Content-Type text/plain
Content-Transfer-Encoding 7bit
X-Trace news.uni-berlin.de 6ejh44IjvX1NhVcxTbdeVgWjbKianvMEzseniqPO9JAw==
Return-Path <random832@fastmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.004
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'received:internal': 0.09; 'python': 0.10; 'jan': 0.11; 'awk': 0.16; 'constructs': 0.16; 'message-id:@webmail.messagingengine.com': 0.16; 'received:10.202': 0.16; 'received:10.202.2': 0.16; 'received:66.111': 0.16; 'received:66.111.4': 0.16; 'received:66.111.4.27': 0.16; 'received:io': 0.16; 'received:messagingengine.com': 0.16; 'received:out3-smtp.messagingengine.com': 0.16; 'received:psf.io': 0.16; 'subject:python.': 0.16; 'wrote:': 0.16; 'memory': 0.17; 'shell': 0.18; 'all,': 0.20; 'header:In-Reply-To:1': 0.24; "doesn't": 0.26; 'command': 0.26; 'fri,': 0.27; 'perl': 0.29; 'print': 0.30; 'file': 0.34; 'that,': 0.34; 'quite': 0.35; 'sometimes': 0.35; 'but': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:10': 0.37; 'really': 0.37; 'received:66': 0.38; 'skip:s 40': 0.38; 'end': 0.39; 'to:addr:python.org': 0.40; 'subject:with': 0.40; 'some': 0.40; 'header:Message-Id:1': 0.61; 'more': 0.63; 'do:': 0.91
DKIM-Signature v=1; a=rsa-sha1; c=relaxed/relaxed; d=fastmail.com; h= content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-sasl-enc :x-sasl-enc; s=mesmtp; bh=q+fN8btAsvmOEteumV+N78w03i4=; b=IcVeMC Ib6s/0rStHCuMOdHRC+oqBaPr0ypWRVufjk1NAD/dA0xI6CDO1//9Y0OCYbVr9qI RGqyqbLNGZCGcp7MT30TX8BQVRRQnjCFYjmDxHPj63fPP6mhGjfHFn+Cgl8/YlZW GliXJcOlLSqLpnndisr6KEQ/V20sBqZgImOOU=
DKIM-Signature v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-sasl-enc:x-sasl-enc; s=smtpout; bh=q+fN8btAsvmOEte umV+N78w03i4=; b=eI5o0fPQh0j2asKWbg6yskjGDQGEs0LW7WlHY97Qu5HRg9n xKE2MKAH6OGTrRjSTs8lFclUQe/0FloIdAGNwgmnHO04fkjGICayrptsIkGAnVcL gCXXENifULoKeNG7mpQqjMZD3hYng25ioGZ0jZ7mqZFkMHrrIehcehuJMCd8=
X-Sasl-Enc JmtAaDMr7jyKgf9nAF7zX/oJzBKgD1EeEl8KRPPvu+9f 1454129918
X-Mailer MessagingEngine.com Webmail Interface - ajax-6cda141f
In-Reply-To <n8hf7c$lqe$1@aspen.stu.neva.ru>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Xref csiph.com comp.lang.python:102277

Show key headers only | View raw


On Fri, Jan 29, 2016, at 23:46, Hongyi Zhao wrote:
> Hi all,
> 
> 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

Well, both of those read the whole file into memory - tac is sometimes
smarter than that, but that makes for a more complex program. And python
doesn't really do "one-liners" like that, so it doesn't look quite as
nice. But combined with some shell constructs you can do:

python <(echo 'import sys;print("".join(reversed(list(sys.stdin))))')

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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