CHAPTER
OTHER EXAMPLES?
In my examples I’ve used numpy to convert the output array into an RGB string for PIL. Since numpy isn’t supported by PyPy this code won’t work there. John Montgomery (http://www.littlespikeyland.com/ thanks!) has submitted a patch which replaces numpy with the array module, modify your code accordingly if you’d like to run it in PyPy:
try:
import array
output = ((o + (256*o) + (256**2)*o) * 8 for o in output)
output = array.array(’I’, output)
#import numpy as np
#output = np.array(output)
#output = (output + (256*output) + (256**2)*output) * 8
import Image
im = Image.new("RGB", (w/2, h/2))
im.fromstring(output.tostring(), "raw", "RGBX", 0, -1)
im.show()
except ImportError as err:
# Bail gracefully if we’re using PyPy
print "Couldn’t import Image or numpy:", str(err)
During the tutorial I mentioned the refactoring tool http://rope.sourceforge.net/ - the GUI is somewhat primitive (I’ve not tried hooking it into other editors yet) but the refactorings work on large files (e.g. 5,000 lines of Python). I’ve used it to refactor unwieldy client code, pulling out functions, timing them, then improving their speed. I’d suggest you check it out.
For this report I’d be interested in seeing the following examples implemented using the same code format as above (I’ve listed them as most-to-least interesting). I’ve not made these myself as I haven’t tried any of them yet. If you want to put an example together, please send it through to me:
I’d like to express my thanks again to the EuroPython 2011 organisers, I had an awful lot of fun preparing and giving this tutorial!