Fixed shelving in the python version.

I ported the correct fix from the perl version over to python.