Skip to content

Make Path subscriptable #139270

@ParadaCarleton

Description

@ParadaCarleton

Feature or enhancement

Proposal:

Path should be subscriptable so I can select components, e.g.

# Add a code block here, if required
In [5]: x = Path("hello/there/general/kenobi")

In [6]: x[0:1] == Path("hello/there")
# Returns true

(This is a more convenient alternative to .parts, which returns a tuple of strings I have to reassemble into a path.)

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytopic-pathlibtype-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions