News for hackers. Stuff that matters.
Re:OpenBSD's Pledge and Unveil from Python by masklinn on Wednesday September 15, 2021 @01:08AM (#28535470)
> Python functions that accept paths, such as open, generally accept either strings or bytes.

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.

There are no comments on this comment yet.