Thread: Python Coolness
05-07-2007, 11:56 AM #1
- Member Since
- Jan 20, 2007
- Oakton, VA USA
- White MacBook Intel C2D 2.2GHz, 2G, 250G, SD, Leopard.
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] >>> >>> gh [<function ab at 0x61270>, <function cd at 0x612b0>, <function ef at 0x612f0>] >>> >>> gh() 0 >>> >>> gh() 1 >>> >>> gh(4, 9) 13
05-07-2007, 06:19 PM #2
- Member Since
- Mar 22, 2007
- Lenovo Z560 Hackintosh -:- '06 iMac -:- iPod Touch 2ndGen
Now that is neat. PHP does that, or something similar, you can call variables as a function just by adding () after them - I did it by accident.[URL="http://beadia.net"]Beadia[/URL - Jewelry Business Management Software]I judge you when you use poor grammar.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
By TamPepper in forum OS X - Development and DarwinReplies: 8Last Post: 12-17-2012, 04:53 PM
By AllanGreen in forum OS X - Apps and GamesReplies: 8Last Post: 07-07-2012, 11:11 PM
By NickBird in forum Switcher HangoutReplies: 0Last Post: 11-14-2008, 02:54 AM
By geekboy2000 in forum Switcher HangoutReplies: 2Last Post: 01-19-2006, 07:30 PM
By pkny in forum OS X - Development and DarwinReplies: 4Last Post: 03-20-2005, 06:17 PM