rxn.utilities.files

Functions

append_to_file(values, filename)

Append an iterable of strings to a file.

count_lines(filename)

param filename

dump_list_to_file(values, filename)

Write an iterable of strings to a file.

dump_tuples_to_files(values, filenames)

Write tuples to multiple files (1st tuple value ends up in 1st file, etc.).

ensure_directory_exists_and_is_empty(directory)

Create a directory if it does not exist already, and raise if not empty.

get_file_size_as_string(file)

Get the file size as a readable string.

is_path_creatable(pathname)

True if the current user has sufficient permissions to create the passed pathname; False otherwise.

is_path_exists_or_creatable(pathname)

True if the passed pathname is a valid pathname for the current OS _and_ either currently exists or is hypothetically creatable; False otherwise.

is_pathname_valid(pathname)

True if the passed pathname is a valid pathname for the current OS; False otherwise.

iterate_lines_from_file(filename)

param filename

iterate_tuples_from_files(filenames)

Read from several files at once, and put the values from the same lines numbers into tuples.

load_list_from_file(filename)

param filename

named_temporary_directory([delete])

Get the path for a temporary directory and create it.

named_temporary_path([delete])

Get the path for a temporary file or directory, without creating it (can be especially useful in tests).

paths_are_identical(*paths)

Whether paths, possibly given in a mix of absolute and relative formats, point to the same file.

raise_if_paths_are_identical(*paths)

Raise an exception if input and output paths point to the same file.

stable_shuffle(input_file, output_file, seed)

Shuffle a file in a deterministic order (the same seed always reorders files of the same number of lines identically).