Or a pathlib.Path, hence os.fspath.
In fact for this specific use case there’s even better:
> os.fsencode(filename)
> Encode path-like filename to the filesystem encoding with 'surrogateescape' error handler, or 'strict' on Windows; return bytes unchanged.
Or a pathlib.Path, hence os.fspath.
In fact for this specific use case there’s even better:
> os.fsencode(filename)
> Encode path-like filename to the filesystem encoding with 'surrogateescape' error handler, or 'strict' on Windows; return bytes unchanged.