Qu

append_text

Builtin index · Collections & strings

result = append_text(path, s) / append_all(path, s)

Input: path, s · Output: result

What it is

path/s are Strs. Appends s to the end of the file at path, creating it if absent. write_text replaces the whole file instead. append_all is the same builtin under the name that pairs with read_all_text — whole file in, whole string out, no handle in either direction — and both spellings stay, since append_text is already in scripts.

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = append_text(path, s) / append_all(path, s)
path Strnot documented yet
s Strnot documented yet
result number
Returns a number: the bytes written.

Examples

From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.

path = "/tmp/qu_scratch_append.txt"
write_text(path, "first line\n")
append_text(path, "second line\n")
print(read_all_text(path))   # "first line\nsecond line\n"

from collections-strings

How it works

write_text(path, s) / append_text(path, s) — the writing counterparts of read_all_text, which existed alone. Saving a string should not need three calls and a handle. append_all(path, s) is append_text under the name that pairs with read_all_text: whole file in, whole string out, no handle. Two spellings rather than a rename, since append_text is already in scripts.

From the note above this builtin in the interpreter, where the reasoning was written down as it was built.

See also

append_all — documented in the same entry.