Check state in python