On 29 December 2010 14:40, Paul Moore firstname.lastname@example.org wrote:
On 29 December 2010 13:36, Michael Foord email@example.com wrote:
I often use python as a calculator or for simple operations using -c. It would be enormously useful if python -c "..." would output on stdout the result of the last evaluated expression in the same way that the interactive interpreter does.
The following outputs nothing:
python -c "12 / 4.1"
So you always have to prefix expressions with print to see the result.
I like the idea, but that's a fairly big semantic change. What about adding an -e option that takes an expression, and prints its value? So you'd have
python -e "12 / 4.1"
(AFAICT, -e is unused at present).
That would be great. I did worry that changing the output would be backwards incompatible with code that shells out to Python using "-c", so a different command line option would be great. So long as it works with multiple statements (semi-colon separated) like the current "-c" behaviour.
I use this trick for finding the source code of Python modules:
$ python -c "import os;print os.__file__[:-1]" /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/os.py
Often in the form:
python -c "import module;print module.__file__[:-1]"
All the best,
Python-ideas mailing list Pythonfirstname.lastname@example.org http://mail.python.org/mailman/listinfo/python-ideas
May you do good and not evil May you find forgiveness for yourself and forgive others May you share freely, never taking more than you give. -- the sqlite blessing http://www.sqlite.org/different.html