[Python-Dev] (Idea) subclassable string: path object?

Just van Rossum just@letterror.com
Fri, 3 Aug 2001 17:11:09 +0200

Jack Jansen wrote:

> One problem I see is that what you'd really like is to overload + and
> split and such on path objects.

Yup. Although it's unclear to me what would be the best behavior for +, because
it could mean several things:

1) p = Path(a_directory) + filename  # os.path.join(a_directory, filename)
2) p = Path(a_file) + ".ext"  # a_file + ".ext"

1) is very useful, but then 2) wouldn't work... So it's not all straightforward.

> But this creates a problem if you then
> pass this path object to something that expects old-fashioned strings:
> if it wants to manipulate that path it will use string operations,
> which suddenly have different semantics...

Yes, that's important to consider, too.

On the other hand: the os.path.* functions could be made aware of the path
object, similar to string.py, except it should fall back to the existing code
when a string gets passed.