Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #12791
| Date | 2011-09-05 22:47 +0200 |
|---|---|
| From | Thomas Jollans <t@jollybox.de> |
| Subject | Re: One line command line filter |
| References | <4725b2c3-d930-4fb0-9fe7-a286d150f9c5@d18g2000yqm.googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.781.1315255602.27778.python-list@python.org> (permalink) |
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 | Next — Previous in thread | Next in thread | Find similar | Unroll 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