luz-io¶
File I/O utilities included with Luz. No installation needed.
Files¶
copy_file(src, dst)¶
Copies the contents of src into dst.
read_file_or(path, default_value)¶
Reads a file and returns its content. Returns default_value if the file does not exist.
write_file_new(path, content)¶
Writes content to a file only if the file does not already exist. Raises an error if the file is already there.
Lines¶
read_lines(path)¶
Reads a file and returns its lines as a list of strings. Newlines are stripped.
write_lines(path, lines)¶
Writes a list of strings to a file, one per line.
append_line(path, line)¶
Appends a single line to a file.
count_lines(path)¶
Returns the number of lines in a file.
read_line(path, n)¶
Returns the nth line of a file (0-indexed). Raises an error if n is out of range.
CSV¶
read_csv(path)¶
Reads a CSV file and returns a list of rows. Each row is a list of strings. The first row is the header.
read_csv_dict(path)¶
Reads a CSV file as a list of dictionaries, using the first row as keys.
write_csv(path, rows)¶
Writes a list of rows (list of lists) to a CSV file.