Skip to content

Instantly share code, notes, and snippets.

@Macadoshis
Created April 21, 2026 14:02
Show Gist options
  • Select an option

  • Save Macadoshis/06ad6fe9144e62c64fbad4dc1d5dded7 to your computer and use it in GitHub Desktop.

Select an option

Save Macadoshis/06ad6fe9144e62c64fbad4dc1d5dded7 to your computer and use it in GitHub Desktop.
split_failed.py
import json
import math
import sys
import os
# Vérification des arguments
if len(sys.argv) < 2:
print("Usage: python split_failed.py <input_file> [parts]")
sys.exit(1)
input_file = sys.argv[1]
parts = int(sys.argv[2]) if len(sys.argv) > 2 else 4 # défaut = 4
# Vérifie que le fichier existe
if not os.path.isfile(input_file):
print(f"Erreur: fichier introuvable -> {input_file}")
sys.exit(1)
with open(input_file, "r", encoding="utf-8") as f:
data = json.load(f)
chunk_size = math.ceil(len(data) / parts)
for i in range(parts):
chunk = data[i * chunk_size:(i + 1) * chunk_size]
output_file = f"output_part_{i+1}.json"
with open(output_file, "w", encoding="utf-8") as f:
json.dump(chunk, f, indent=2)
print(f"Done: {parts} fichiers générés.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment