Skip to content

Feature: Support pathlib objects #833

@jrwrigh

Description

@jrwrigh

Describe the bug, what's wrong, and what you expect:

Python's standard library has a pathlib module that acts as a OS agnostic method of manipulating paths. I quite like it and many libraries support it as a replacement input for strings when file paths are requested. At least pyvista.UnstructuredGrid() does not support pathlib objects, though I'd imagine even more do.

To add flexibility (and increase the "pythonic"ness of the library), it might be worth also adding support for other python file-type objects. See code in numpy.loadfile and it's supporting function isfileobj.

I'd imagine this would need to be implemented in _load_file.


To Reproduce

import pyvista as pv
from pathlib import Path
vtuFilePath = Path(r'./test.vtu')
pv.UnstructuredGrid(vtuFilePath)
 # Errors with 'TypeError: Cannot work with input type <class 'pathlib.PosixPath'>'

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions