using python with -c (as a inline execution in shell)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • les ander

    #1

    using python with -c (as a inline execution in shell)

    Hi,
    in perl one can do all sorts of stuff in a single line form the command shell.
    python has the -c option.
    it is easy to do stuff like,
    python -c "print 10+20"
    etc statements
    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?
    Also, is there is site that talkes about doing this kind of stuff?
    the man pages in xterm are pretty sparse and don't say that much
    thanks
  • Skip Montanaro

    #2
    Re: using python with -c (as a inline execution in shell)


    les> python -c "from sys import stdin; for x in stdin: print x"

    les> gives a syntax error.

    les> Anyone one know how to do this?

    How about:

    % python -c 'from sys import stdin[color=blue]
    > for x in stdin:
    > print x
    > '[/color]
    hi there
    bye
    hi there

    bye

    Skip

    Comment

    • Simon Brunning

      #3
      Re: using python with -c (as a inline execution in shell)

      On 16 Nov 2004 07:44:19 -0800, les ander <les_ander@yaho o.com> wrote:[color=blue]
      > 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.[/color]

      If you really must do this, there's always PyOne:
      <http://www.unixuser.or g/~euske/pyone/>.

      Wouldn't touch it with a bargepole, myself.

      --
      Cheers,
      Simon B,
      simon@brunningo nline.net,

      Comment

      Working...