Let’s say you’re messing about with Zope, and you want to access something that’s not on your $PYTHONPATH. Usually, you’d just add a .pth file to your site-packages directory, right? But what if you don’t want to?
a = ‘/path/to/desired/directory/’
import foo # Used to get an error on this import!
That last sys.path.remove is necessary so you don’t start stacking up multiple, identical entries in the sys.path list, especially with the long-running Zope process.