segment write by python, algorithm by use