-->

Saturday, March 9, 2013

Executing Python multi-line statements in the one-line command-line


There are several alternatives to execute python code from commandline. The  one I prefer is n.1, but check them out all:

echo -e "import sys\nfor r in range(10): print 'rob'" | python
or w/out pipes:
python -c "exec(\"import sys\\nfor r in range(10): print 'rob'\")"
or
(echo "import sys" ; echo "for r in range(10): print 'rob'") | python

No comments:

Post a Comment