porting code to python3.x with os patch