34 lines
1.2 KiB
Python
34 lines
1.2 KiB
Python
# def iter_and_append_from_csv(csvfile):
|
|||
|
|
# """
|
||
|
|
# Read and iterate over a CSV file.
|
||
|
|
# Args:
|
||
|
|
# csvfile (file): A file object representing the CSV file to read.
|
||
|
|
|
||
|
|
# Yields:
|
||
|
|
# list: A row from the CSV file as a list of strings.
|
||
|
|
# """
|
||
|
|
# csvreader = csv.reader(csvfile)
|
||
|
|
# for row in csvreader:
|
||
|
|
# yield row
|
||
|
|
|
||
|
|
# def _read_csv_data(filename: str, row_indices: List[int], col_indices: List[int]) -> List[List[str]]:
|
||
|
|
# """
|
||
|
|
# Helper function to read and extract specific rows and columns from a CSV file.
|
||
|
|
|
||
|
|
# Args:
|
||
|
|
# filename (str): Path to the CSV file.
|
||
|
|
# row_indices (List[int]): List of row indices to extract.
|
||
|
|
# col_indices (List[int]): List of column indices to extract.
|
||
|
|
|
||
|
|
# Returns:
|
||
|
|
# List[List[str]]: A list of rows, where each row is a list of values at the specified column indices.
|
||
|
|
# """
|
||
|
|
# try:
|
||
|
|
# with open(filename, 'r', encoding='utf-8') as csvfile:
|
||
|
|
# csvfile_data = list(iter_and_append_from_csv(csvfile))
|
||
|
|
# return [[csvfile_data[row][col] for col in col_indices] for row in row_indices]
|
||
|
|
# except FileNotFoundError as e:
|
||
|
|
# print(e)
|
||
|
|
# return []
|
||
|
|
|