platypush/plugins/csv/__init__.py
def read(self,
             filename: str,
             delimiter: str = ',',
             quotechar: Optional[str] = '"',
             start: int = 0,
             limit: Optional[int] = None,
             reverse: bool = False,
             has_header: bool = None,
             column_names: Optional[List[str]] = None,
             dialect: str = 'excel'):
        """
        Gets the content of a CSV file.

        :param filename: Path of the file.
        :param delimiter: Field delimiter (default: ``,``).
        :param quotechar: Quote character (default: ``"``).
        :param start: (Zero-based) index of the first line to be read (starting from the last if ``reverse`` is True)
            (default: 0).
        :param limit: Maximum number of lines to be read (default: all).
        :param reverse: If True then the lines will be read starting from the last (default: False).
        :param has_header: Set to True if the first row of the file is a header, False if the first row
            isn't expected to be a header (default: None, the method will scan the first chunk of the file
            and estimate whether the first line is a header).
        :param column_names: Specify if the file has no header or you want to override the column names.
        :param dialect: CSV dialect (default: ``excel``).
        """

        filename = self._get_path(filename)
        column_names = column_names or []
        csv_args = {
            'delimiter': delimiter,
            'quotechar': quotechar,
            'dialect': dialect,
        }

        if has_header is None and not column_names:
            column_names = self._parse_header(filename, **csv_args)
            has_header = len(column_names) > 0

        rows = []
        with open(filename, 'r', newline='') as f:
            for i, row in enumerate(csv.reader(self.lines(f, reverse=reverse), **csv_args)):
                if not row or i < start:
                    continue
                if limit and len(rows) >= limit + (1 if has_header else 0):
                    break

                rows.append(dict(zip(column_names, row)) if column_names else row)

        if has_header:
            rows.pop(-1 if reverse else 0)
        return rows

        Gets the content of a CSV file.

        :param filename: Path of the file.
        :param delimiter: Field delimiter (default: ``,``).
        :param quotechar: Quote character (default: ``"``).
        :param start: (Zero-based) index of the first line to be read (starting from the last if ``reverse`` is True)
            (default: 0).
        :param limit: Maximum number of lines to be read (default: all).
        :param reverse: If True then the lines will be read starting from the last (default: False).
        :param has_header: Set to True if the first row of the file is a header, False if the first row
            isn't expected to be a header (default: None, the method will scan the first chunk of the file
            and estimate whether the first line is a header).
        :param column_names: Specify if the file has no header or you want to override the column names.
        :param dialect: CSV dialect (default: ``excel``).
        
Gets the content of a CSV file.
Gets the content of a CSV file .
def read(self,
             filename: str,
             delimiter: str = ',',
             quotechar: Optional[str] = '"',
             start: int = 0,
             limit: Optional[int] = None,
             reverse: bool = False,
             has_header: bool = None,
             column_names: Optional[List[str]] = None,
             dialect: str = 'excel'):
        filename = self._get_path(filename)
        column_names = column_names or []
        csv_args = {
            'delimiter': delimiter,
            'quotechar': quotechar,
            'dialect': dialect,
        }
        if has_header is None and not column_names:
            column_names = self._parse_header(filename, **csv_args)
            has_header = len(column_names) > 0
        rows = []
        with open(filename, 'r', newline='') as f:
            for i, row in enumerate(csv.reader(self.lines(f, reverse=reverse), **csv_args)):
                if not row or i < start:
                    continue
                if limit and len(rows) >= limit + (1 if has_header else 0):
                    break
                rows.append(dict(zip(column_names, row)) if column_names else row)
        if has_header:
            rows.pop(-1 if reverse else 0)
        return rows
def read ( self , filename : str , delimiter : str = ',' , quotechar : Optional [ str ] = '"' , start : int = 0 , limit : Optional [ int ] = None , reverse : bool = False , has_header : bool = None , column_names : Optional [ List [ str ] ] = None , dialect : str = 'excel' ) : filename = self . _get_path ( filename ) column_names = column_names or [ ] csv_args = { 'delimiter' : delimiter , 'quotechar' : quotechar , 'dialect' : dialect , } if has_header is None and not column_names : column_names = self . _parse_header ( filename , ** csv_args ) has_header = len ( column_names ) > 0 rows = [ ] with open ( filename , 'r' , newline = '' ) as f : for i , row in enumerate ( csv . reader ( self . lines ( f , reverse = reverse ) , ** csv_args ) ) : if not row or i < start : continue if limit and len ( rows ) >= limit + ( 1 if has_header else 0 ) : break rows . append ( dict ( zip ( column_names , row ) ) if column_names else row ) if has_header : rows . pop ( - 1 if reverse else 0 ) return rows
Gets the content of a CSV file.
Gets the content of a CSV file .
"""
        Gets the content of a CSV file.

        :param filename: Path of the file.
        :param delimiter: Field delimiter (default: ``,``).
        :param quotechar: Quote character (default: ``"``).
        :param start: (Zero-based) index of the first line to be read (starting from the last if ``reverse`` is True)
            (default: 0).
        :param limit: Maximum number of lines to be read (default: all).
        :param reverse: If True then the lines will be read starting from the last (default: False).
        :param has_header: Set to True if the first row of the file is a header, False if the first row
            isn't expected to be a header (default: None, the method will scan the first chunk of the file
            and estimate whether the first line is a header).
        :param column_names: Specify if the file has no header or you want to override the column names.
        :param dialect: CSV dialect (default: ``excel``).
        """
self
filename
str
Path of the file.
Path of the file .
delimiter
str
Field delimiter (default: ``,``).
Field delimiter ( default : ` ` ` ` ) .
quotechar
Optional[str]
Quote character (default: ``"``).
Quote character ( default : ` ` " ` ` ) .
start
int
(Zero-based) index of the first line to be read (starting from the last if ``reverse`` is True)
(default: 0).
( Zero - based ) index of the first line to be read ( starting from the last if ` ` reverse ` ` is True ) ( default : 0 ) .
limit
Optional[int]
Maximum number of lines to be read (default: all).
Maximum number of lines to be read ( default : all ) .
reverse
bool
If True then the lines will be read starting from the last (default: False).
If True then the lines will be read starting from the last ( default : False ) .
has_header
bool
Set to True if the first row of the file is a header, False if the first row
isn't expected to be a header (default: None, the method will scan the first chunk of the file
and estimate whether the first line is a header).
Set to True if the first row of the file is a header False if the first row isn ' t expected to be a header ( default : None the method will scan the first chunk of the file and estimate whether the first line is a header ) .
column_names
Optional[List[str]]
Specify if the file has no header or you want to override the column names.
Specify if the file has no header or you want to override the column names .
dialect
str
CSV dialect (default: ``excel``).
CSV dialect ( default : ` ` excel ` ` ) .