better python code to be less posix dependent