468,115 Members | 2,077 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,115 developers. It's quick & easy.

python -c option

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
Jul 18 '05 #1
1 1800
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

Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

15 posts views Thread by Hansan | last post: by
reply views Thread by bruce | last post: by
reply views Thread by Kurt B. Kaiser | last post: by
3 posts views Thread by marco Starglider | last post: by
reply views Thread by M.-A. Lemburg | last post: by
3 posts views Thread by didacticone | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.