def _read_py(self, fin_py, get_goids_only, exclude_ungrouped):
        """Read Python sections file. Store: section2goids sections_seen. Return goids_fin."""
        goids_sec = []
        with open(fin_py) as istrm:
            section_name = None
            for line in istrm:
                mgo = self.srch_py_goids.search(line)     # Matches GO IDs in sections
                if mgo:
                    goids_sec.append(mgo.group(2))
                elif not get_goids_only and "[" in line:
                    msec = self.srch_py_section.search(line)  # Matches sections
                    if msec:
                        secstr = msec.group(3)
                        if section_name is not None and goids_sec:
                            self.section2goids[section_name] = goids_sec
                        if not exclude_ungrouped or secstr != HdrgosSections.secdflt:
                            section_name = secstr
                            self.sections_seen.append(section_name)
                        else:
                            section_name = None
                        goids_sec = []
            if section_name is not None and goids_sec:
                self.section2goids[section_name] = goids_sec
        return goids_sec
Read Python sections file. Store: section2goids sections_seen. Return goids_fin.