Connecting Tech Pros Worldwide Help | Site Map
 
 
LinkBack Thread Tools Search this Thread
  #1  
Old July 18th, 2005, 06:40 PM
les ander
Guest
 
Posts: n/a
Default 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



  #2  
Old July 18th, 2005, 06:40 PM
Skip Montanaro
Guest
 
Posts: n/a
Default 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
  #3  
Old July 18th, 2005, 06:40 PM
Simon Brunning
Guest
 
Posts: n/a
Default Re: using python with -c (as a inline execution in shell)

On 16 Nov 2004 07:44:19 -0800, les ander <les_ander@yahoo.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.org/~euske/pyone/>.

Wouldn't touch it with a bargepole, myself.

--
Cheers,
Simon B,
simon@brunningonline.net,
http://www.brunningonline.net/simon/blog/
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 205,414 network members.