CSV¶
class CSVReader
¶
CSVReader(f, newline="\n", delimiter=",", quotechar="\"", has_header=False, comment="#", max_line=1024, as_dict=False))
-
f
is the csv path or its file descriptor. The object will automatically handle both type of inputs. If passedf
is the path string, the file will be automatically opened. -
newline
is the string used as newline by the reader. Default is"\n"
; -
delimiter
is the char used as delimiter by the reader. Default is","
; -
quotechar
is the char used as quote identifier by the reader. Default is"\""
; -
has_header
if set toTrue
the reader will expect a header on top of the csv. Default isFalse
; -
comment
is the char used as comment identifier by the reader. Default is"#"
; -
max_line
is the maximum number of lines that the reader will read. Default is1024
; -
as_dict
if set toTrue
the reader will return a data as dictionary, ifFalse
as a list. Default isFalse
;
The CSVReader
objects are iterable.
method nrow
¶
nrow()
method read
¶
read()
method close
¶
close()
class CSVWriter
¶
CSVWriter(f, newline="\n", delimiter=',', as_dict=False)
-
f
is the csv path or its file descriptor. The object will automatically handle both type of inputs. If passedf
is the path string, the file will be automatically opened. -
newline
is the string used as newline by the writer. Default is"\n"
; -
delimiter
is the char used as delimiter by the writer. Default is","
; -
as_dict
if set toTrue
, the writer will use a dictionary as data. Default isFalse
;
method close
¶
close()
method write_header
¶
write_header(header)
header
is the header list to write.
method write
¶
write(row, as_row=False)
-
row
is the row to write. Depending onas_dict
this might be a list or a dictionary. -
as_row
if set toTrue
the writer will ignore the header length (if present) and write all the row nevertheless.