SparkseePython3 6.1.0
sparksee.CSVReader Class Reference

CSVReader interface. More...

Inheritance diagram for sparksee.CSVReader:
Inheritance graph
Collaboration diagram for sparksee.CSVReader:
Collaboration graph

Public Member Functions

 set_separator (self, sep)
 Sets the character used to separate fields in the file.
 set_num_lines (self, num_lines)
 Used to limit the number of lines that will be read.
 close (self)
 Closes the reader.
 set_locale (self, locale_str)
 Sets the locale that will be used to read the file.
 read (self, row)
 Reads the next row as a string array.
 set_multilines (self, num_extralines)
 Allows the use of fields with more than one line.
 open (self, file_path)
 Opens the source file path.
 reset (self)
 Moves the reader to the beginning.
 set_start_line (self, start_line)
 Sets the number of lines to be skiped from the beginning.
 set_single_line (self)
 Only allows single line fields.
 get_row (self)
 The row number for the current row.
 __init__ (self)
 Constructs CSVReader.
 set_quotes (self, quotes)
 Sets the character used to quote fields.

Detailed Description

CSVReader interface.

A very simple CSV reader.

It works as any other RowReader, but open must be called once before the first read operation.

Using the format RFC 4180.

Except: leading and trailing spaces, adjacent to CSV separator character, are trimmed.

You can use your own separators and quote characters. By default the separator is the comma (,) and the quote character is the double quotes ("). Fields with multiple lines can be allowed (and the maximum lines specified), but the default is a single line. The locale string can be used to set the language, country and the file encoding. The format must be "[language_territory][.codeset]". But only the file encoding is being used in the current version. The languages supported are: "en_US", "es_ES" and "ca_ES". <br> The file encodings supported are: "utf8" and "iso88591". For example: To don't change the default locales, use an empty string: "".<br> To read a file in utf8 with the default language settings use ".utf8".<br> To read a file in iso88591 with English language use: "en_US.iso88591".

Check out the 'Data import' section in the SPARKSEE User Manual for more details on this.

Author
Sparsity Technologies http://www.sparsity-technologies.com

Member Function Documentation

◆ close()

sparksee.CSVReader.close ( self)

Closes the reader.

Exceptions
IOErrorIf the close fails.

Reimplemented from sparksee.RowReader.

◆ get_row()

sparksee.CSVReader.get_row ( self)

The row number for the current row.

Returns
The current row number; 0 if there is no current row.
Exceptions
IOErrorIf it fails.

Reimplemented from sparksee.RowReader.

◆ open()

sparksee.CSVReader.open ( self,
file_path )

Opens the source file path.

File can be optionally compressed in GZIP format.

Parameters
file_path[in] CSV file path.
Exceptions
IOErrorIf bad things happen opening the file.

◆ read()

sparksee.CSVReader.read ( self,
row )

Reads the next row as a string array.

Parameters
row[out] A string list with each comma-separated element as a separate entry.
Returns
Returns true if a row had been read or false otherwise.
Exceptions
IOErrorIf bad things happen during the read.

Reimplemented from sparksee.RowReader.

◆ reset()

sparksee.CSVReader.reset ( self)

Moves the reader to the beginning.

Restarts the reader.

Returns
true if the reader can be restarted, false otherwise.
Exceptions
IOErrorIf bad things happen during the restart.

Reimplemented from sparksee.RowReader.

◆ set_locale()

sparksee.CSVReader.set_locale ( self,
locale_str )

Sets the locale that will be used to read the file.

Parameters
locale_str[in] The locale string for the file encoding.

◆ set_multilines()

sparksee.CSVReader.set_multilines ( self,
num_extralines )

Allows the use of fields with more than one line.

Parameters
num_extralines[in] Maximum number of extra lines for each column (0==unlimited, N==N+1 total rows).

◆ set_num_lines()

sparksee.CSVReader.set_num_lines ( self,
num_lines )

Used to limit the number of lines that will be read.

Parameters
num_lines[in] The maximum number of lines to read (0 == unlimited)

◆ set_quotes()

sparksee.CSVReader.set_quotes ( self,
quotes )

Sets the character used to quote fields.

Parameters
quotes[in] Quote character.
Exceptions
RuntimeErrorFor any issue

◆ set_separator()

sparksee.CSVReader.set_separator ( self,
sep )

Sets the character used to separate fields in the file.

Parameters
sep[in] Separator character.
Exceptions
RuntimeErrorFor any issue

◆ set_start_line()

sparksee.CSVReader.set_start_line ( self,
start_line )

Sets the number of lines to be skiped from the beginning.

Parameters
start_line[in] The line number to skip for start reading