Python 3 porting:  file and objects

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