python -c option
Klaus Alexander Seistrup
spam at magnetic-ink.dk
Sun Jul 6 23:32:22 CEST 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
> 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?
python -c 'print 2+2'
> 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
python -c 'import sys; exec(sys.stdin.readline()); print "%d%%" % (prog*100,)'
but why not write a small python script instead?
><> unselfish actions pay back better
More information about the Python-list