Bases: FileTypeHandler
Handler for extracting text from CSV files.
Methods:
Source code in textxtract/handlers/csv.py
| class CSVHandler(FileTypeHandler):
"""Handler for extracting text from CSV files."""
def extract(self, file_path: Path, config: Optional[dict] = None) -> str:
try:
encoding = (config or {}).get("encoding", "utf-8")
with open(file_path, "r", encoding=encoding, newline="") as f:
reader = csv.reader(f)
return "\n".join([", ".join(row) for row in reader])
except Exception as e:
raise ExtractionError(f"CSV extraction failed: {e}")
async def extract_async(
self, file_path: Path, config: Optional[dict] = None
) -> str:
import asyncio
return await asyncio.to_thread(self.extract, file_path, config)
|
Functions
extract
extract(file_path, config=None)
Source code in textxtract/handlers/csv.py
| def extract(self, file_path: Path, config: Optional[dict] = None) -> str:
try:
encoding = (config or {}).get("encoding", "utf-8")
with open(file_path, "r", encoding=encoding, newline="") as f:
reader = csv.reader(f)
return "\n".join([", ".join(row) for row in reader])
except Exception as e:
raise ExtractionError(f"CSV extraction failed: {e}")
|
extract_async
async
extract_async(file_path, config=None)
Source code in textxtract/handlers/csv.py
| async def extract_async(
self, file_path: Path, config: Optional[dict] = None
) -> str:
import asyncio
return await asyncio.to_thread(self.extract, file_path, config)
|