|
Fixing Apple’s iTunes U Python Sample Code
Category: All Articles
Mac OS X is a remarkable collection of software—nearly every scripting language important in the UNIX world is included as a part of any OS X installation. Yet although OS X is bundled with Perl, Python, and Ruby, it is not necessarily the case that the scripting language bundled with the latest version of Mac OS X will be the latest version of that scripting language. After all, it takes time for Apple to verify that an open source tool will work properly in OS X—so you may find your copy of OS X is a little behind the rest of the UNIX world when it comes to any open source tool. In addition, it is not hard to imagine that Apple does most of its development work on Macs running OS X. So it is reasonable to suppose that any sample code that Apple releases will be tested against the software installed for the most recent iteration of OS X. Such code, while portable in principle, may not be portable in fact because the scripting language used to create it in OS X may not be the most recent version of the scripting language running on other platforms (or even on a Mac that has been updated with a more recent version of the scripting language) Such is the case with Apple’s Python sample code for iTunes U. Apple’s code will work with Python 2.3…but there have been some pretty significant changes in Python since version 2.3 (as of this writing, the current version of Python running on Mac OS X 10.6 is 2.6.1). If you attempt to run Apple’s Python sample code for iTunes U “out of the box” in a Python 2.6.1 environment, you’ll find it doesn’t work. This article explains how to fix the code so that it will work. Begin by opening
to this:
Next, you’ll need to simplify lines 146 to 151 from this:
to this:
And that’s it—you’re done—Apple’s iTunes U sample code will now work with Python 2.6.1. As always with Python, be mindful of spacing and tabbing…if you haven’t worked with it before, you should be aware that Python is especially finicky about how whitespace is used in code. Generally speaking, if you copy-and-paste this fix, be sure to match the style of surrounding lines of code…if nested code uses spaces to set it off from surrounding code, you must use (the same number of) spaces in any code you paste into a script; if tabs, tabs. Apple uses tabbing in the iTunes U sample code, so you should match Apple’s style when substituting the fix. |
Articles by Category
This Article's Tags
Related Articles
|