meyelens.fileio

class meyelens.fileio.FileWriter(path_to_file, filename: str = '', append: bool = False, sep: str = ';')[source]

Bases: object

Simple synchronous text file writer.

This class creates a timestamped .txt file and exposes convenience methods to write either a single string (one line) or a list of values separated by a custom delimiter.

Notes

  • This writer is synchronous: each call writes directly to disk.

  • The filename is always timestamped to reduce accidental overwrites.

  • The file is opened immediately on initialization and must be closed by calling close().

write(stringa: str) None[source]

Write a single line to the file.

Parameters:

stringa (str) – Line content. A newline character is automatically appended.

write_sv(lista) None[source]

Write a list of values as a separator-joined line.

Parameters:

lista (iterable) – Values to serialize. Each element is converted to str. The resulting line is written with a trailing newline.

is_open() bool[source]

Check whether the underlying file handle is still open.

Returns:

True if the file is open, otherwise False.

Return type:

bool

close() None[source]

Close the underlying file handle.

Notes

After closing, further write attempts will raise an exception.

class meyelens.fileio.BufferedFileWriter(path_to_file, filename: str = '', buffer_size: int = 100, metadata=None, headers=None, sep: str = ';')[source]

Bases: object

Buffered asynchronous text file writer.

This writer uses an in-memory queue.Queue as a buffer and a background thread to flush lines to disk. This is useful for time-critical data acquisition loops where direct disk writes would introduce latency.

The file format is:

  • optional metadata lines (prefixed with #)

  • a header row (separator-joined)

  • data rows (one per buffered entry)

Notes

  • The background thread is started automatically at initialization.

  • Call close() to stop the thread and ensure all queued data is written.

  • If the buffer is full, new entries are discarded and a print warning is emitted (per your request, no logging is used).

write(string: str) None[source]

Queue a pre-formatted line for writing.

Parameters:

string (str) – The line to write (without a trailing newline). A newline will be appended by the writer thread.

Notes

If the buffer is full, the value is discarded and a warning is printed.

write_sv(lista) None[source]

Queue a list of values as a separator-joined line.

Parameters:

lista (iterable) – Values to serialize. Each element is converted to str and joined with sep.

close() None[source]

Stop the background thread and close the file.

This method: 1. Signals the thread to stop 2. Waits for the thread to finish flushing queued data 3. Closes the underlying file handle

Notes

Always call this method to avoid losing buffered data.