tecio.open

On this page

tecio.open#

tecio.open(path, mode='r', **kwargs)#

Open a Tecplot file for reading, writing, or appending.

Selects the correct format handler from the file extension and returns the appropriate reader or writer. All handles are context managers.

Parameters:
  • path (str | os.PathLike) – File path. Extension determines the format handler:

    • .szplt → tecio.szl

    • .plt / .bin / .bbin / .bbin8 → tecio.plt

    • .dat / .tec → tecio.dat

  • mode (str) – Access mode — mirrors Python’s built-in open():

    • 'r' – Open Tecplot file for reading.

    • 'w' – Open Tecplot file for writing, truncating the file first.

    • 'x' – Open Tecplot file for exclusive creation, failing if the file already exists.

    • 'a' – Append new zones to an existing file. The file is stream-copied to a temporary file; on close the temporary atomically replaces the original. Raises FileNotFoundError if the file does not exist (use 'w' to create a new file).

    • 'a+' – Same as 'a' but the returned handle also exposes the full read API populated from the original file.

    Legacy PLT files (v75, v107, v111) can only be opened with 'r'; 'a' and 'a+' raise ValueError for them.

  • **kwargs – Forwarded to the underlying handler constructor. The accepted keyword arguments differ by mode — see the tables below.

Keyword Args (modes 'r', 'w', 'x'):

Forwarded directly to the format’s Read or Write constructor.

For reading — no keyword arguments are accepted; all metadata is read from the file.

For writing ('w' and 'x'):

Keyword

Default

Description

title

""

Dataset title string embedded in the file header.

variables

None

Variable name list. For SZL and PLT this may be deferred to the first write_ordered_zone(), write_fe_zone(), write_femixed_zone(), or write_poly_zone() call. Required at open time for DAT.

file_type

FileType.FULL

One of FULL, GRID, or SOLUTION.

Keyword Args (modes 'a', 'a+'):

title, variables, and file_type default to the values read from the existing file. In most cases you should not pass these. Providing them will override the source file when written out.

Returns:

Raises:
  • ValueError – Unsupported file extension, unrecognised mode, or 'a'/'a+' on a legacy PLT file (v75, v107, v111).

  • FileNotFoundError – 'r', 'a', or 'a+' on a missing file.

  • FileExistsError – 'x' on an existing file.

Examples

Read a file:

>>> with tecio.open("flow.szplt") as tec:
...     x = tec.zones[0].variables["x"].values

Write a new file, deferring variable names to the first zone:

>>> with tecio.open("out.szplt", "w", title="Run 1") as tec:
...     tec.write_ordered_zone(data=[x, y, p], variables=["x", "y", "p"])

Append a new zone to an existing file:

>>> with tecio.open("out.szplt", "a") as tec:
...     tec.write_ordered_zone(data=[x2, y2, p2], solution_time=2.0)

Append and read in the same session:

>>> with tecio.open("out.szplt", "a+") as tec:
...     prev_p = tec.zones[-1].variables["p"].values
...     tec.write_ordered_zone(data=[x2, y2, prev_p * 0.9])