Rebased PR#382 'Fixed loaddata raising IOError' from rollstudio

This PR obsoletes PR#382 'Fixed loaddata raising IOError' from rollstudio.
It is the rebased version of that patch, as required by @yakky.