Test the direction of a line using Python

Hi all,

I want to write a script that creates mullions for a facade. The input is a polyline. The problem is that when the line (the segment of the input polyline) is divided by a length, the next segment can be reversed in the direction and a small segment is left. I want to test the following segment and if it is reversed in the direction, then flip it, so that polyline is flowing in one direction. Well, the image explains it better.

Thanks!