python -c option

Klaus Alexander Seistrup spam at magnetic-ink.dk
Sun Jul 6 23:32:22 CEST 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




More information about the Python-list mailing list