using python with -c (as a inline execution in shell)
Alex Martelli
aleaxit at yahoo.com
Tue Nov 16 15:47:15 EST 2004
les ander <les_ander at yahoo.com> wrote:
> but suppose I want to read from the stdin (piped) i don't know how to do
> this since python -c "from sys import stdin; for x in stdin: print x"
>
> gives a syntax error.
>
> Anyone one know how to do this?
Not _good_ ways, but:
import sys; print sys.stdin.read()
import sys; sys.stdout.write(sys.stdin.read())
import sys; sys.stdout.writelines(sys.stdin)
are some approaches. None matches the double-spacing effect you appear
to be after, but changing every '\n' into two ain't _that_ hard, e.g.
import sys; print sys.stdin.read().replace('\n','\n\n')
etc, will give kinda the same doublespacing your approach would give if
it worked. Still, Python just isn't oneline-oriented...
Alex
More information about the Python-list
mailing list