Results 1 to 2 of 2

Thread: Python Coolness

  1. #1

    mathogre's Avatar
    Member Since
    Jan 20, 2007
    Oakton, VA USA
    White MacBook Intel C2D 2.2GHz, 2G, 250G, SD, Leopard.
    Python Coolness
    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[2](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.

  2. #2

    knightlie's Avatar
    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=""]Beadia[/URL - Jewelry Business Management Software]
    I judge you when you use poor grammar.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Python and cv2
    By TamPepper in forum macOS - Development and Darwin
    Replies: 8
    Last Post: 12-17-2012, 03:53 PM
  2. Using Python
    By AllanGreen in forum macOS - Apps and Games
    Replies: 8
    Last Post: 07-07-2012, 10:11 PM
  3. Python
    By NickBird in forum Switcher Hangout
    Replies: 0
    Last Post: 11-14-2008, 01:54 AM
  4. Accidental Coolness: Next Year, Maybe a PowerMac G5?
    By geekboy2000 in forum Switcher Hangout
    Replies: 2
    Last Post: 01-19-2006, 06:30 PM
  5. PYTHON PROGRAMMERS!!! how do i compile/run linux-based python code on OS X
    By pkny in forum macOS - Development and Darwin
    Replies: 4
    Last Post: 03-20-2005, 05:17 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts