[Python-ideas] Working with Path objects: p-strings?

Steven D'Aprano steve at pearwood.info
Tue Mar 29 07:21:33 EDT 2016


On Tue, Mar 29, 2016 at 12:57:02PM +0200, Michel Desmoulin wrote:
> 
> 
> Le 29/03/2016 12:36, Paul Moore a écrit :

> > I don't intend to get sucked into the role of "defender of not
> > inheriting", but one point that should probably be considered is that
> > on Unix, it is possible to have paths which are *not* valid Python
> > strings. How would those work in an inherit-from-str environment? I
> > suspect that using surrogateescape is the answer here, but I don't
> > know.
> 
> How does str(path) does it ? Because ultimatly, we pass strings to
> open() and os.stuff. So we need it as strings anyway.

Actually, open and os.* will accept bytes paths, at least on Linux.

Unless I'm missing something, pathlib doesn't support bytes filenames. 
So the question doesn't come up. Any path you can use with pathlib is a 
valid Python string, because you can only create paths using Python 
strings.

So if I have a Linux file b'\xD8\x01', I can't create a path object to 
work with it.


-- 
Steve


More information about the Python-ideas mailing list