def findPyc(): for file_xml in findFilexml(folder): filexml = open(file_xml).readlines() for file in filexml: if file.find("Path") > 0: path = file.split("")[1].split("")[0] path = os.path.join("/", path) if path.endswith(".pyc"): [x for x in path if x.find(".pyc") > 0] fileList = [x for x in path if x.find(".pyc") > 0] print fileList