CSV¶
class CSVReader¶
CSVReader(f, newline="\n", delimiter=",", quotechar="\"", has_header=False, comment="#", max_line=1024, as_dict=False))
-
fis the csv path or its file descriptor. The object will automatically handle both type of inputs. If passedfis the path string, the file will be automatically opened. -
newlineis the string used as newline by the reader. Default is"\n"; -
delimiteris the char used as delimiter by the reader. Default is","; -
quotecharis the char used as quote identifier by the reader. Default is"\""; -
has_headerif set toTruethe reader will expect a header on top of the csv. Default isFalse; -
commentis the char used as comment identifier by the reader. Default is"#"; -
max_lineis the maximum number of lines that the reader will read. Default is1024; -
as_dictif set toTruethe reader will return a data as dictionary, ifFalseas 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)
-
fis the csv path or its file descriptor. The object will automatically handle both type of inputs. If passedfis the path string, the file will be automatically opened. -
newlineis the string used as newline by the writer. Default is"\n"; -
delimiteris the char used as delimiter by the writer. Default is","; -
as_dictif set toTrue, the writer will use a dictionary as data. Default isFalse;
method close¶
close()
method write_header¶
write_header(header)
headeris the header list to write.
method write¶
write(row, as_row=False)
-
rowis the row to write. Depending onas_dictthis might be a list or a dictionary. -
as_rowif set toTruethe writer will ignore the header length (if present) and write all the row nevertheless.