Mac Python Development

The Python programming language serves as the foundation for many web and desktop applications. Because of its widespread use and the nature of its open development, many Unix-like systems come prepackaged with the Python interpreter and Python libraries. Mac OS, built on the Mach kernel, also contains the Python interpreter built in. Users interested in learning Python or developing Python applications on the Mac OS system can jump directly into a project, or get some of the Python development tools available for Mac OS.

  1. Python on MacOS

    • The Python interpreter comes preinstalled on Mac computers. Since it is already built into the Mac operating system, the programmer need not download anything to start Python development. However, due to the Mac OS development process, the version of Python incorporated into the operating system usually lags behind the latest release of Python. A programmer can download the latest version from Python (python.org).

    Using Python on Mac: IDLE

    • A Python programmer starting on the Mac operating system can begin in two different ways. The first method involves invoking the Python interactive development environment, or IDLE, from the Mac "Terminal." The programmer can access the Terminal application from the "Utilities" folder located under the "Go" submenu of the main Finder toolbar. The programmer invokes IDLE in the Terminal by entering the command "python". The following prompt will appear, allowing the programmer to enter code at will. IDLE will execute code as entered, as in the following example:

      [GCC 4.2.1 (Apple Inc. build 5646)] on darwin

      Type "help", "copyright", "credits" or "license" for more information.

      >>> print "Hello World"

      'Hello World'

    Using Python on Mac: Text Editor

    • The programmer can also write code into a text editor to create a python file. The programmer can write the code, save the file to the proper format and run the code through the Python interpreter. A Python program written in a text editor must contain the "shebang" line as the first line of code, followed by the code itself. The programmer must then save the file with the ".py" extension, and then run the program by invoking the interpreter and the file name, such as "python filename.py". The following code shows an example of a print program written in a text editor:

      #!/usr/bin/python //"shebang" line for Mac OS

      print "Hello World"

    Specific Functionality for Mac

    • Python for Mac OS contains a range of functions specific for Mac development. Python programmers on the Mac can use the AppleScript language in Python to manage data and communication between running programs on Mac OS. Mac OS Python also contains application programming libraries, or APIs, to interact with the native "Cocoa" environment, which Mac programmers use to develop native applications. Python also contains a special "py2app" library that allows developers to bundle stand-alone Python packages for distribution to other Mac computers.

    Development Environments for Mac

    • While some programmers prefer to develop on tools such as straightforward text editors, others like fully functional development environments, or IDEs, that manage large projects with large amounts of code. Boa Constructor (boa-constructor.sourceforge.net) serves as a cross platform IDE that works on Macs as well as Windows. The Eclipse IDE (eclipse.org) serves as in IDE for numerous languages, primarily Java, but ranging from Python to C++ to PHP. The Xcode application, native to Macs and free to Mac developers, also can serve as a Python IDE with only a few tweaks.

Related Searches:

References

Resources

Comments

Related Ads

Featured