from pathlib import Path def supprimer_lignes_logger(fichier: str) -> None: path = Path(fichier) lignes_filtrees = [] skip_block = False parentheses_balance = 0 with path.open("r", encoding="utf-8") as f: for ligne in f: stripped = ligne.lstrip() # Détection du début d'un appel logger if not skip_block and stripped.startswith("logger"): skip_block = True parentheses_balance += ligne.count("(") - ligne.count(")") continue if skip_block: parentheses_balance += ligne.count("(") - ligne.count(")") if parentheses_balance <= 0: skip_block = False parentheses_balance = 0 continue lignes_filtrees.append(ligne) path.write_text("".join(lignes_filtrees), encoding="utf-8") if __name__ == "__main__": supprimer_lignes_logger("sage_connector.py")