python -c option

Discussion in 'Python' started by Mike, Jul 6, 2003.

  1. Mike

    Mike Guest

    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
    Mike, Jul 6, 2003
    #1
    1. Advertising

  2. 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
    Klaus Alexander Seistrup, Jul 6, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Julien ROUZIERES

    g++ -pg option and -shared option

    Julien ROUZIERES, Dec 21, 2004, in forum: C++
    Replies:
    1
    Views:
    715
    GianGuz
    Dec 21, 2004
  2. Cas
    Replies:
    5
    Views:
    790
    Kevin Jones
    Aug 28, 2006
  3. Kevin Blount

    page.aspx?option - how to detect "option"

    Kevin Blount, Nov 28, 2006, in forum: ASP .Net
    Replies:
    6
    Views:
    605
    =?Utf-8?B?RWVyYWo=?=
    Nov 28, 2006
  4. John

    Regex for <option> ... </option>

    John, Jan 23, 2009, in forum: Perl Misc
    Replies:
    10
    Views:
    236
    Eric Pozharski
    Jan 29, 2009
  5. Mark Kolber
    Replies:
    4
    Views:
    342
Loading...

Share This Page