| Subcribe via RSS

Python Magazine for December available for download now! (and I’m in it)

December 24th, 2007 | | Posted in Programming, Python

IMG_1102.JPGI just saw Dougs blog post about the december issue of PyMag hitting the site (and going to print) on my iPhone, so I quickly put Abby in the loving care of my grandmother to make a christmas-eve post!

The issues of PyMag have been great so far, and I'm mainly excited about this months because the article I spent a lot of time on - "Python Threads and the Global Interpreter Lock" is in it! You should buy it!

It the first time anything I've written has shown up in something resembling real print media. Feel free to lambast me, email me comments, etc. I hope I did a decent job of explaining and benchmarking things - and now that it's out, I will be re-pick-up all of the parallel library benchmarking I have been doing.

Hopefully I'll get a chance after xmas to do more writing provided this one doesn't suck that bad.

Alex Martelli on the differences between Python and Ruby

December 18th, 2007 | | Posted in Programming, Python

I saw this google-groups post cross reddit this morning, and I really consider it one of the most lucid discussions on the differences between the two languages.

Others no doubt base their choice of programming languages on just
such issues, and they generate the hottest debates -- but to me that's
just an example of one of Parkinson's Laws in action (the amount on
debate on an issue is inversely proportional to the issue's actual
importance).

Myself? I've always found that Ruby's tendency to lean more towards perl-like syntax to be the turnoff (line noise for the loose), not the actual concepts behind the language, although Alex's points about "too much dynamicity" are quite good. Ruby does have a lot of good features that may eventually find their way into Python. Although, I'd much rather see Erlang-ish features without the dense syntax.

A new statistics module from the GHOP?

December 16th, 2007 | | Posted in Programming, Python

Saw this pop up on pypi: Statlib 1.0, the actual google-code project is here. It's popping out of the Google Highly Open Par... GHOP-Python work. Sweet.

Fixing the Leopard install of Python, and virtualenv for the win.

December 16th, 2007 | | Posted in Programming, Python

So, as a followup to my previous post - PyObjc 2: Leopard, Python 2.5.1 and You. A commenter pointed out that the python.org installation of python only adds a new version of Python to the /Library/Frameworks/ directory - it does not replace the default one in /System/Library/Frameworks/.

So, in order to "return" to my "pristine" leopard state, all I actually had to do was remove this line in my .bash_profile (which I hadn't noticed - my .bash_profile is about 250 lines long):

PATH="/Library/Frameworks/Python.framework/Versions/Current/bin:${PATH}"

Then I simply moved the /Library/Frameworks/Python.framework directory to some other name (just to be anal). The only side-effect being that I "lost" all of my installed python modules in the python.org install's site-packages directory.

The latter is fine, because I've been meaning to 'clean house' with the cruft I've built up compulsively downloading stuff from pypi and doing other work. Since I'm now dealing with a 'cleaned out' version, I took the chance to clean-install virtualenv and setup a nice /jesse/python_vms directory. I added a 'default' profile that gets auto-loaded on login, and added a few functions to let me switch in-between them. Example:

# Python VMs override(s)
VMDIR="/Users/jesse/python_vms"
DEFAULT_PY_ENV="$VMDIR/default"
SANDBOX_PY_ENV="$VMDIR/sandbox"
# Load the default python env by, uh, default!
. $DEFAULT_PY_ENV/bin/activate
pydefault () { . $DEFAULT_PY_ENV/bin/activate; }
pysandbox () { . $SANDBOX_PY_ENV/bin/activate; }

In my case, the default profile will only load my work-profile, while my sandbox is going to be where all the pypi modules I tinker with go. The nice thing of course, is that the activate script included with the virtualenv env overrides my default $PATH to make sure the local bin directory is used prior to the main $PATH, which means I don't need to worry about conflicts with the default easy_install that comes with Leopard.

Now I've got the best of all worlds, the default install that has all the leopard pyobjc goodies, and a nice clean sandbox.

Of course, this doesn't even cover the horror which is my /subversion directory - which at last look, I had to write a shell-script wrapper to auto-update the largish number of svn projects I watch/sync.

Django Weblog: The Django Book is done.

December 16th, 2007 | | Posted in Programming, Python

The Django guys finished up their book - and now the complete text is available online and free! I'd recommend buying a hard-copy, but that's just because I prefer books to reading online (and supporting the effort is cool too). More here: Django Weblog: The Django Book is done.

pygooglechart

December 15th, 2007 | | Posted in Programming, Python

Google's chart's API was released, what, a week or two ago? And yet someone has already put together an excellent start of a python module to interact with it - enter pygooglechart 0.1.1: "A complete Python wrapper for the Google Chart API" (main site here).

[pontificate]
In another life, I worked for a large "web technology" company, and during that time, I swore off working on web-based end-user systems due to massive burnout and general dislike of where things seemed to be heading (j2ee). With the rise of technologies like Django, Amazon's web services, Google's web services and so many others, the web seems more attractive now than it did then. Although I still want to focus on the technology behind them.
[/pontificate]

PyObjC: Run in Python automator action.

December 15th, 2007 | | Posted in Apple, Programming, Python

This is an excellent post from yesterday - the author outlines how, using 10.5 PyObjC bindings and the Leopard Automator, you can add a "run python script" automator action.

I particularly like his followup post on where he outlines how to use the new 'run in python' action to ship files off to Amazon's S3 storage.

The latter of the two posts actually hooked me up with the "boto" python module - which looks like an excellent module for interacting with Amazon's web services, something I've been examining recently for a side-project.

PyObjc 2: Leopard, Python 2.5.1 and You.

December 14th, 2007 | | Posted in Apple, Programming, Python

So, most everyone know that Apple released OS/X Leopard a bit ago - I was on the early adopter train, and have not had any problems (except for the occasional spaces crash because I mash buttons fast).

One of the cooler things that came out with Leopard was a completely overhauled PyObjC built-in. Including Webkit bindings, and many other things (see here and here for more details), a built-in version of twisted and many other things.

However, I was a moron. I was knee-deep in debugging a problem and compulsively replaced my came-with-leopard version of Python with the python.org python 2.5.1 build. (Anyone with tips on how to undo this, please let me know).

Once I dropped in the 2.5.1 version: poof. I managed to wipe out all of the delicious stuff built into my shiny new OS, which made me a sad panda. Once the PyObjC 2.0 stuff hit the PyObjC SVN tree (here) though, I was filled with hope that I could at least restore the PyObjC stuff.

Alas! It was not to be. Come to find out, there's a hard coded string in the macpython makefile which causes the pyobjc build to use the wrong SDK and puke and die. After much wailing and gnashing of teeth, I gave up not realizing what the problem was. You should see a problem like this:

C compiler: gcc -arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -fno-strict-aliasing -Wno-long-double -no-cpp-precomp -mno-fused-madd -fno-common -dynamic -DNDEBUG -g -O3

compile options: '-I/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5 -c'
gcc: Modules/_Foundation_nscoder.m
Modules/_Foundation_nscoder.m: In function ‘imp_NSCoder_encodeArrayOfObjCType_count_at_’:
Modules/_Foundation_nscoder.m:220: error: ‘NSUInteger’ undeclared (first use in this function)
Modules/_Foundation_nscoder.m:220: error: (Each undeclared identifier is reported only once
Modules/_Foundation_nscoder.m:220: error: for each function it appears in.)
Modules/_Foundation_nscoder.m:220: error: syntax error before ‘count’
Modules/_Foundation_nscoder.m:228: error: syntax error before ‘i’
Modules/_Foundation_nscoder.m:249: error: ‘count’ undeclared (first use in this function)
Modules/_Foundation_nscoder.m:256: error: ‘i’ undeclared (first use in this function)

However, last night I was snowed-in at work and in between bug fixes for work, I managed to dig up a post (with fix) on the issue I was having (thanks Barry).

The short answer is sync the tree from subversion, and then edit the following file:

/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/config/Makefile

And remove the "-isysroot /Developer/SDKs/MacOSX10.4u.sdk" chunk of text. Drop into the sync'ed svn tree and run the 02-develop-all.sh script. Now I can happily import WebKit:

Python 2.5.1 (r251:54869, Apr 18 2007, 22:08:04)
[GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import WebKit
>>>

I download all the Python Cookbook recipes

December 10th, 2007 | | Posted in Programming, Python

I download all the Python Cookbook recipes: "I download all the Python Cookbook recipes"

I am simply at a loss for words. I can't decide if this is fantastic, an abomination or a piece of performance art. Although the prose is exciting.

(Via Recipes from the Python Cookbook.)

Guido van Rossum’s Weblog: Python 3.0 alpha 2 Released!

December 7th, 2007 | | Posted in Programming, Python

Guido van Rossum's Weblog: Python 3.0 alpha 2 Released!: "Another milestone in Python 3000 development: alpha 2 is released. Now with immutable bytes!"

(Via Planet Python.)