Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Yet another command line calculator' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Yet another command line calculator
Authored by: delza on Feb 02, '05 01:27:30PM

Another tip for using Python from the command-line: for short scripts you don't need to start the interactive editor, you can just pass the script to the interpreter with -C, but you will have to print the results explicitly.

For example:

# 2 to the power of 16
python -c "print 2 ** 10"

# hex representation of 1024
python -c "print hex(1024)"

# base-10 representation of 0x400
python -c "print int('0x400', 16)"

# cosine of pi/4
python -c "import math; print math.cos(math.pi * 0.25)"

etc...



[ Reply to This | # ]
Yet another command line calculator
Authored by: adrianm on Feb 02, '05 01:50:10PM
I presume we've already covered applescript?

osascript -e '3+4/8'
And you can use the Services menu when in most text boxes (incl. TextEdit, Pages, etc) to evaluate any applescript expression.

[ Reply to This | # ]