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

Wes Turner wes.turner at gmail.com
Sun Mar 27 01:25:26 EDT 2016


On Sat, Mar 26, 2016 at 6:51 PM, Koos Zevenhoven <k7hoven at gmail.com> wrote:

> On Sun, Mar 27, 2016 at 1:13 AM, Greg Ewing <greg.ewing at canterbury.ac.nz>
> wrote:
>
>> [...]
>> This feels like a slippery slope to me. If we include
>> special syntax for pathnames, why shouldn't we have it
>> for dates and times? Regular expressions? URLs? JSON
>> data? SQL queries? XML data? Where do we draw the line?
>>
>
> OT:
>
> To be honest, I do think it feels like URL:s are becoming (or have become)
> just as important as paths, and that pathlib.Path should in the future work
> with URLs just like it now works with windows and posix paths. The
> difference between "http://domain.xyz/" and "C:\\" is not huge.
>

Here's some preliminary research (w/ links) that may be of use here:
https://www.reddit.com/r/Python/comments/1r7h1t/python_objects_for_working_with_urls_and_uris/

* URLObject (+1 from me)
* rdflib.term.URIRef
* fs.path

Differences between fs paths and URIs:

* urlencode

IDK why I seem to remember having concluded that it would make sense to
store paths as tuples / lists and join by os.path.sep


> I also think there should be a Python type (stdlib or builtin), which
> handles JSON objects nicer than dicts do and has its own literal syntax.
>

collections.OrderedDict almost works here, except that .keys() and
.values() must be casted to e.g. lists (because otherwise the comparison is
between KeysView / ValuesView ~iterators)

   to_json = _repr_json_  # "IPython repr method examples"
   #
https://gist.github.com/westurner/be22dba8110be099a35e#file-ordereddefaultdict-py-L110

Then, if Path is not a subclass of str (or, py2 __builtin__.unicode, as in
https://github.com/jaraco/path.py/blob/master/path.py ), comparisons
between JSON-ified path objects will fail.


>
>  - Koos
>
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160327/0153cef6/attachment.html>


More information about the Python-ideas mailing list