nschloe/meshio

[BUG] ElementTree.write does not accept file handles

cc-a opened this issue · 0 comments

cc-a commented

Describe the bug

The write method of meshio._cxml.etree.ElementTree accepts only filenames. This causes an error when trying to write e.g. vtu files and passing a file handle. Seems like a simple fix so I'd be happy to put a PR together if you agree this requires resolution.

To Reproduce

with open("test.vtu", "w") as f:
...     mesh.write(f, "vtu")

Traceback (most recent call last):
File "", line 2, in
File "/home/ccaveayl/projects/Solidity-GUI/.venv/lib/python3.10/site-packages/meshio/_mesh.py", line 241, in write
write(path_or_buf, self, file_format, **kwargs)
File "/home/ccaveayl/projects/Solidity-GUI/.venv/lib/python3.10/site-packages/meshio/_helpers.py", line 188, in write
return writer(filename, mesh, **kwargs)
File "/home/ccaveayl/projects/Solidity-GUI/.venv/lib/python3.10/site-packages/meshio/vtu/_vtu.py", line 908, in write
tree.write(filename)
File "/home/ccaveayl/projects/Solidity-GUI/.venv/lib/python3.10/site-packages/meshio/_cxml/etree.py", line 57, in write
with open(filename, "w") as f:
TypeError: expected str, bytes or os.PathLike object, not TextIOWrapper

Diagnose

meshio==5.3.4

Did I help?

If I was able to resolve your problem, consider sponsoring my work on meshio, or buy me a coffee to say thanks.