[Python-ideas] Working with Path objects: p-strings?
Chris Barker - NOAA Federal
chris.barker at noaa.gov
Wed Mar 30 10:26:51 EDT 2016
>> . They actually want the benefits of both, the pure datastructure with its convenience methods and the dirty str-like thing with its convenience methods.'''
>
> The desire is not "str vs. Path"; its "Path + str". (at least from what I can tell)
I don't think so. ( though I agree with the lazy part). People want
paths to be a strings so that they will work with all the code that
already works with strings. That's the primary motivator.
If early versions of Python had a path object, there'd be no problem.
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.
I suppose a __path__ magic method would be the "proper" way to do
this, but it's really not necessary, it can be handled by the libs
themselves.
I think there is a fine plan in place, but if more flexibility is
required, something like numpy's asarray() would be handy -- it passes
actual Numpy arrays through untouched, and makes various efforts to
make an array out of anything else.
It's remarkably easy and effective to write functions that take
virtually anything remotely array like -- lists, tuples, array.arrays,
custom objects, etc.
-CHB
More information about the Python-ideas
mailing list