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

Joseph Martinot-Lagarde contrebasse at gmail.com
Fri Apr 1 07:42:08 EDT 2016


Paul Moore <p.f.moore at ...> writes:

> > People want paths to be a strings so that they will work with all the code
> > that already works with strings.
> 
> Correct. That's the prime motivation. But you then say
> 
> > But whatever happened to duck typing? Paths don't need to BE strings.
> > Rather, everything that needs a path needs to accept anything that
> > acts like a path.
> 
> But "all the code that already works with strings" doesn't do that. If
> we're allowed to change that code then a simple
> 
>     patharg = getattr(patharg, 'path', patharg)
> 
> is sufficient to work with path objects or strings.
> 
I think you have it backwards here: the problem is not updating code that
you can change, it's using any external library that uses paths as strings.

When I use a library from pypi, I won't add a new line in every function
using a string representing a path. When if I use path.py, I can directly
pass paths to any library without changing its code.



More information about the Python-ideas mailing list