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


Groups > comp.lang.python > #12791

Re: One line command line filter

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <t@jollybox.de>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.073
X-Spam-Evidence '*H*': 0.86; '*S*': 0.01; 'python:': 0.05; 'python': 0.08; 'subsequent': 0.15; '"import': 0.16; 'illegal.': 0.16; 'subject:command': 0.16; 'wrote:': 0.16; 'seems': 0.20; 'header :In-Reply-To:1': 0.22; 'command': 0.24; 'skip:_ 20': 0.28; 'print': 0.29; 'to:addr:python-list': 0.33; 'header:User-Agent:1': 0.34; 'similar': 0.35; 'something': 0.37; 'subject:: ': 0.39; 'received:192': 0.39; 'missing': 0.39; 'to:addr:python.org': 0.39; '"for': 0.67; 'received:62': 0.70; 'subject:line': 0.73; 'subject:One': 0.77; 'from:addr:t': 0.84; 'jon': 0.84
Date Mon, 05 Sep 2011 22:47:23 +0200
From Thomas Jollans <t@jollybox.de>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:6.0) Gecko/20110816 Thunderbird/6.0
MIME-Version 1.0
To python-list@python.org
Subject Re: One line command line filter
References <4725b2c3-d930-4fb0-9fe7-a286d150f9c5@d18g2000yqm.googlegroups.com>
In-Reply-To <4725b2c3-d930-4fb0-9fe7-a286d150f9c5@d18g2000yqm.googlegroups.com>
X-Enigmail-Version 1.3.1
OpenPGP id=5C8691ED
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.781.1315255602.27778.python-list@python.org> (permalink)
Lines 13
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1315255603 news.xs4all.nl 2456 [2001:888:2000:d::a6]:48844
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:12791

Show key headers only | View raw


On 05/09/11 22:38, Jon Redgrave wrote:
> It seems unreasonably hard to write simple one-line unix command line
> filters in python:
> 
> eg: ls | python -c "<something>  print x.upper()"
> 
> to get at sys.stdin or similar needs an import, which makes a
> subsequent for-loop illegal.
> python -c "import sys; for x in sys.stdin(): print x" <<- SyntaxError
> 
> Am I missing something obvious?

ls | python -c "for line in __import__('sys').stdin: print (line.upper())"

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


Thread

One line command line filter Jon Redgrave <jredgrave@capisco.com> - 2011-09-05 13:38 -0700
  Re: One line command line filter Thomas Jollans <t@jollybox.de> - 2011-09-05 22:47 +0200
    Re: One line command line filter Jon Redgrave <jredgrave@capisco.com> - 2011-09-05 14:32 -0700
      Re: One line command line filter Terry Reedy <tjreedy@udel.edu> - 2011-09-05 19:02 -0400
  Re: One line command line filter Terry Reedy <tjreedy@udel.edu> - 2011-09-05 18:21 -0400
    Re: One line command line filter Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-09-06 09:18 +1000
      Re: One line command line filter Terry Reedy <tjreedy@udel.edu> - 2011-09-05 21:25 -0400
      Re: One line command line filter Hans Mulder <hansmu@xs4all.nl> - 2011-09-06 13:15 +0200
  Re: One line command line filter Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-09-06 09:29 +1000
  Re: One line command line filter John Wiegley <jwiegley@gmail.com> - 2011-09-06 01:51 -0500
  Re: One line command line filter Peter Otten <__peter__@web.de> - 2011-09-06 09:53 +0200

csiph-web