Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > python -c option

Reply
Thread Tools

python -c option

 
 
Mike
Guest
Posts: n/a
 
      07-06-2003
I am very new to Python and read the docs section about having python run
commands from the command line. I have been successful with:

python -c "print 'Hello'"

It prints Hello

In the interpreter I can type 2+2 and it will return 4 but how do I do
that from the command line? I have tried a few things without success.

What I am really after is to do some command line processing where the
output of grep is returning "prog=.01234" and I want to beautify it so it
prints "12%"

Maybe I should mess with bash but I am new to *nix in general and I wanted
to learn Python.

Thanks,
Mike
 
Reply With Quote
 
 
 
 
Klaus Alexander Seistrup
Guest
Posts: n/a
 
      07-06-2003
Mike wrote:

> I am very new to Python and read the docs section about having
> python run commands from the command line. I have been successful
> with:
>
> python -c "print 'Hello'"
>
> It prints Hello
>
> In the interpreter I can type 2+2 and it will return 4 but how do
> I do that from the command line?


#v+

python -c 'print 2+2'

#v-

> What I am really after is to do some command line processing where
> the output of grep is returning "prog=.01234" and I want to beautify
> it so it prints "12%"


Assuming the output is "prog=.1234", you _could_ do ugly things like

#v+

python -c 'import sys; exec(sys.stdin.readline()); print "%d%%" % (prog*100,)'

#v-

but why not write a small python script instead?


// Klaus

--
><> unselfish actions pay back better

 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Regex for <option> ... </option> John Perl Misc 10 01-29-2009 11:04 PM
page.aspx?option - how to detect "option" Kevin Blount ASP .Net 6 11-28-2006 09:21 PM
DHCP relay agent versus Option 3; Routers Option lcorrigan Cisco 2 09-27-2006 05:18 PM
no 'option' in aspx file means 'option'="false"? Cas ASP .Net 5 08-28-2006 10:36 AM
g++ -pg option and -shared option Julien ROUZIERES C++ 1 12-21-2004 02:30 PM



Advertisments