Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> 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.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: