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: 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 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 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 " 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())"