New To Mac-Forums?

Welcome to our community! Join the discussion today by registering your FREE account. If you have any problems with the registration process, please contact us!

Get your questions answered by community gurus Advice and insight from world-class Apple enthusiasts Exclusive access to members-only contests, giveaways and deals

Join today!

 
Start a Discussion
 

Mac-Forums Brief

Subscribe to Mac-Forums Brief to receive special offers from Mac-Forums partners and sponsors

Join the conversation RSS
OS X - Development and Darwin Discussion and questions about development for Mac OS X.

Python Coolness


Post Reply New Thread Subscribe

 
Thread Tools
mathogre

 
mathogre's Avatar
 
Member Since: Jan 20, 2007
Location: Oakton, VA USA
Posts: 3,269
mathogre has a brilliant futuremathogre has a brilliant futuremathogre has a brilliant futuremathogre has a brilliant futuremathogre has a brilliant futuremathogre has a brilliant futuremathogre has a brilliant futuremathogre has a brilliant futuremathogre has a brilliant futuremathogre has a brilliant futuremathogre has a brilliant future
Mac Specs: White MacBook Intel C2D 2.2GHz, 2G, 250G, SD, Leopard.

mathogre is offline
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:

Code:
>>> 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]()
0
>>> 
>>> gh[1]()
1
>>> 
>>> gh[2](4, 9)
13

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.
QUOTE Thanks
knightlie

 
knightlie's Avatar
 
Member Since: Mar 22, 2007
Location: UK
Posts: 1,463
knightlie is just really niceknightlie is just really niceknightlie is just really niceknightlie is just really nice
Mac Specs: Lenovo Z560 Hackintosh -:- '06 iMac -:- iPod Touch 2ndGen

knightlie is offline
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.
QUOTE Thanks

Post Reply New Thread Subscribe


« Choosing a Language. | Start OpenOffice from java »
Thread Tools

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread
Thread Starter
Forum
Replies
Last Post
Mail.app and JunkMatcher problem Porphyro OS X - Apps and Games 1 07-29-2006 11:47 AM
Accidental Coolness: Next Year, Maybe a PowerMac G5? geekboy2000 Switcher Hangout 2 01-19-2006 06:30 PM
PYTHON PROGRAMMERS!!! how do i compile/run linux-based python code on OS X pkny OS X - Development and Darwin 4 03-20-2005 05:17 PM
Python Problems dr_springfield OS X - Development and Darwin 3 05-12-2004 01:04 AM

All times are GMT -4. The time now is 06:09 AM.

Powered by vBulletin
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
X

Welcome to Mac-Forums.com

Create your username to jump into the discussion!

New members like you have made this community the ultimate source for your Mac since 2003!


(4 digit year)

Already a member?