def segments(seg_type=None):
    """Iterate segments based on type

        Args:
            seg_type: type of segment e.g. SEG_CODE

        Returns:
            iterator of `Segment` objects. if seg_type is None , returns all segments
            otherwise returns only the relevant ones
    """

    for index in xrange(idaapi.get_segm_qty()):
        seg = Segment(index=index)
        if (seg_type is None) or (seg.type == seg_type):
            yield Segment(index=index)
Iterate segments based on type

        Args:
            seg_type: type of segment e.g. SEG_CODE

        Returns:
            iterator of `Segment` objects. if seg_type is None , returns all segments
            otherwise returns only the relevant ones