[Python-Dev] Fwd: I was just thinking that os.path could use some love...

Cameron Simpson cs at zip.com.au
Wed Jan 30 23:01:41 CET 2013


On 30Jan2013 13:26, Guido van Rossum <guido at python.org> wrote:
| Thoughts on os.path? What happened to the idea of a new path object?  [...]
| From: Talin <viridia at gmail.com> [...]
| On Wed, Jan 30, 2013 at 11:33 AM, Guido van Rossum <guido at python.org> wrote:
| > Hmm... Mind if I just forward to python-dev? IIRC there's been some
| > discussion about a newfangled path object, but I lost track of where
| > the discussion went. (Or you can post there yourself. :-)
| 
| Sure - forward away. Is this the same as the path object idea that was
| floated 5 years ago? I've yet to see any set of convenience methods
| for paths that are so compelling as to be worth all of the time and
| energy needed to update all of the various APIs which now expect paths
| to be passed in as strings.

Speaking for myself, I've been having some usefulness with making "URL"
objects that are subclasses of str. That lets me pass them to all the
things that already expect strs, while still having convenience methods.

Combined with a little factory function to make a "URL" from a bare
str should it be needed, it has worked fairly well. It is certainly not
seamless all the time...

Eg:
  U = URL(s)    # returns s if already an instance of _URL
  len(U)        # I'm still a string
  U.startswith("http:")
  U.scheme      # eg "http"
  U.hrefs       # fetch content, parse as HTML, return links

Just a thought on supporting code expecting strings.

Cheers,
-- 
Cameron Simpson <cs at zip.com.au>

Outside of a dog, a book is a man's best friend.  Inside of a dog, it's too
dark to read. - Groucho Marx


More information about the Python-Dev mailing list