Python 3 porting:  file and objects

I've re introduced a _py3_compat.py. I will keep this small, only the the really repetitive stuff.