Adapt Python code for attribute.