Archive of articles classified as' "Python"

Back home

Download large file in chunks with Python using urllib2 to a temporary directory


No Comments

Install Python Imaging Library (PIL) on OS X 10.6 (Snow Leopard)


I look a bit painful to do this at first, but here is a very simple solution.

  1. Install brew
  2. run ‘brew instal PIL’
  3. Brew install PIL at /usr/local/Cellar/pil/1.1.7/lib/python2.6/site-packages
  4. Symlink the PIL site-packages to your Python site-packages in /Library/Python/2.6/site-packages

    ln -s /usr/local/Cellar/pil/1.1.7/lib/python2.6/site-packages/PIL /Library/Python/2.6/site-packages/PIL


Simple Graphical Python Profiling with RunSnakeRun


sudo aptitude install python-wxtools

sudo easy_install runsnakerun

sudo aptitude install python-profiler

(If you are using Debian check this out :

run with:

python -m cProfile -o barbazzr.profile

Check out the output with:
runsnake name.profilepython -m cProfile -o barbazzr.profile

No Comments

Django 1.2 CSRF verification failed


Are you updating an old Django  project to use Django 1.2, and getting this error message when you try to login to the Django admin page?

403 Forbidden

CSRF verification failed. Request aborted.

Reason given for failure:

CSRF cookie not set.

Then you need to add  ‘django.middleware.csrf.CsrfViewMiddleware’, and  ‘django.middleware.csrf.CsrfResponseMiddleware’ your file. Mine looks like this:


Thanks to the Django docs


Find the path of a Python module


The builtin inspect module makes it easy to find out information about the modules you are loading. Just ‘import inspect’ and use inspect.getfile

Python 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit (Intel)] on win32
Type “help”, “copyright”, “credits” or “license” for more information.
>>> import inspect
>>> import random
>>> inspect.getfile(random)

1 Comment