Member Since: Jan 20, 2007
Location: Oakton, VA USA
Mac Specs: White MacBook Intel C2D 2.2GHz, 2G, 250G, SD, Leopard.
05-07-2007, 11:56 AM
Python is one of the coolest languages.
I was just playing around with it today, beginning a little program I'm writing for fun. Problem was that I'd like to be able to easily call functions based on some condition. "Easily" is the operative term.
And it *is* easy. Define the functions, place their names in a named list, and then call the list item as a function of condition. Here's a simple example:
>>> def ab() :
... return 0
>>> def cd() :
... return 1
>>> def ef(q, r) :
... return q+r
>>> gh = [ab, cd, ef]
[<function ab at 0x61270>, <function cd at 0x612b0>, <function ef at 0x612f0>]
>>> gh(4, 9)
Evil Math Ogre Kgh-Ra
Integrate me. Differentiate me.
You can't hurt me. I'm e^x. Ha ha ha!
Homepage | Gallery
I was on the M-F honor roll for July 2007.