Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Chris Angelico Newsgroups: comp.lang.python Subject: Re: Mimick tac with python. Date: Sat, 30 Jan 2016 15:56:17 +1100 Lines: 14 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de j6tbw8wZoNdIuWouvGFcbAyTOuWO1U0+JCNMxar5aJ5A== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.007 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'received:209.85.223': 0.03; 'cc:addr:python-list': 0.09; 'argument,': 0.09; 'python': 0.10; 'jan': 0.11; 'skip:p 40': 0.15; '2016': 0.16; 'awk': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'stuff.': 0.16; 'subject:python.': 0.16; 'wrote:': 0.16; 'python?': 0.18; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'sat,': 0.23; 'header :In-Reply-To:1': 0.24; "doesn't": 0.26; 'command': 0.26; 'message- id:@mail.gmail.com': 0.27; 'perl': 0.29; 'print': 0.30; 'file': 0.34; 'received:google.com': 0.35; 'but': 0.36; 'received:209.85': 0.36; 'possible': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'received:209': 0.38; 'end': 0.39; 'enough': 0.39; 'subject:with': 0.40; 'easy': 0.60; '30,': 0.63; 'reverse': 0.66; 'chrisa': 0.84; 'grabbing': 0.84; 'short-hand': 0.84; 'to:none': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=4SdCEX8UcFf3LEehsap2rjnDoYHG8B1AIKiAbmM3hvY=; b=ePAKdv1UbNbJCJBcuauxn9EFruyWK1+SrRqiXcOSMp1+Ta478FuuiXqS1XsEPj21IC bH4BHflYPmg0kD++MRsBDCUV25thAK9SFc20JvXMArSC5vCTaufJSWvyOSZbGb3zhZb+ Y4z6xKYvklTGBmTwf3tq0Ns/txRs4lbf0neGdnYFO6XvoK5PKeROXiI3QdmslhWBw0KA iPpd2iMP4JZQOHWDjTYfhlmM5z/Vep2qQzhXpCbh1cRuXotNX9SoZwfcMRMQuTZox5V6 U0Omn77Poan0K4VwsKi23nIqEHjOSLxdoChLwqvcL92Oz63FfnFp66QEGhGIhYTBl2L8 IGYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:cc:content-type; bh=4SdCEX8UcFf3LEehsap2rjnDoYHG8B1AIKiAbmM3hvY=; b=fqzFZ6SqM/Ul8v9hSeANK+Uy3zvuO0yBXsblYKB/zlx6B4w5LpkJAkmGmKV1VMU+yY 82ZpbKiZ+f/Ks9Q22L8hqaNhdt0SGe6n1ebYxLumbclL2hyhp+oecpu0RKIwafz3kcUd D07PNPeIPtcJw5kVf/eBosBpkZ0Yh0lCuvpn4WlBkjVvh+eacqg9K2YXx7KhEbgHzPNn 8T2Z7qt0SrVrg4uUE1pP3MJnuChVl54JTX0eg14P2sm3wmWdjt8BDbmFOjB03GBC+H5s xDATk1+veWBXI+kcHj00YeSi5H176MHCKNfGXr0aPhvPzEt+clubLlMhtlItvdv+gmRb p1zA== X-Gm-Message-State: AG10YOSjQjpUKGqmF6aDVskAz6CBw5rLumb5QizxQW3AETssU6tb/PBAhXGVajSd/SHQ3PcLCTFVpSZEGPTYwg== X-Received: by 10.107.14.73 with SMTP id 70mr13388133ioo.31.1454129777892; Fri, 29 Jan 2016 20:56:17 -0800 (PST) In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:102278 On Sat, Jan 30, 2016 at 3:46 PM, Hongyi Zhao 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