-
Notifications
You must be signed in to change notification settings - Fork 18
pyio.write_lines
fabian-flassig edited this page Mar 18, 2026
·
2 revisions
Writes a table of strings to a text file, one entry per line.
pyio.write_lines(path, lines [, encoding])| Parameter | Type | Description |
|---|---|---|
path |
string |
The file path where the text should be written |
lines |
{ (string)* } |
A table of strings, each entry represents one line |
encoding |
string (optional)
|
Encoding of the output file ("utf8", "utf8-bom", "utf16le", "utf16be", "ascii") |
| Type | Description |
|---|---|
nil |
No return value |
Writing the following Lua table
local lines = {
"# Sample file",
"Hello World",
"",
"Pi = 3.14"
}
pyio.write_lines("sample.txt", lines)will create a text file with the following content:
# Sample file
Hello World
Pi = 3.14Each entry in the table is written as a separate line in the file. A newline is automatically appended after every line.
If a table entry is nil or cannot be converted to a string, it is treated as an empty line.
Supported encodings include UTF-8 (with or without BOM), UTF-16 (little endian and big endian), and ASCII. If no encoding is specified, UTF-8 is used by default.
For UTF-16 encodings, Windows-style line endings (CR+LF) are written. For UTF-8 and ASCII, line endings are written as LF.
Minimum PYTHA Version: V26