Skip to content

add setter for pathlib.stem #126537

@thawn

Description

@thawn

Feature or enhancement

Proposal:

It would be nice to have the option to modify the stem of a file name directly.

Say I have a Path '/tmp/myfile.npy':

file_path = Path('/tmp/myfile.npy')

if the file exists, I want to change the file name to '/tmp/myfile-1.npy', in order to avoid overwriting it, I currently need to do the following:

if file_path.exists():
    file_path = file_path.parents / (file_path.stem + '-1' + file_path.suffix)

It would be much cleaner, if I could instead just do the following:

if file_path.exists():
    file_path.stem += '-1'

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

    type-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions