INNER CODE UNIT · Python

line_count

Dicklesworthstone/claude_code_agent_farm · claude_code_agent_farm.py:110

def line_count(file_path: Path) -> int:
    """Count lines in a file"""
    try:
        # Try UTF-8 first, then fall back to latin-1
        try:
            with file_path.open("r", encoding="utf-8") as f:
                return sum(1 for _ in f)
        except UnicodeDecodeError:
            # Try common encodings
            for encoding in ["latin-1", "cp1252", "iso-8859-1"]:
                try:
                    with file_path.open("r", encoding=encoding) as f:
                        return sum(1 for _ in f)
                except UnicodeDecodeError:
                    continue
            # Last resort: ignore errors
            with file_path.open("r", encoding="utf-8", errors="ignore") as f:
                return sum(1 for _ in f)

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…