python code from MAC