[issue28560] Implement `PurePath.startswith` and `PurePath.endswith`

2016-10-30 Thread SilentGhost
Changes by SilentGhost : -- resolution: wont fix -> rejected stage: -> resolved ___ Python tracker ___

[issue28560] Implement `PurePath.startswith` and `PurePath.endswith`

2016-10-30 Thread Ram Rachum
Ram Rachum added the comment: Thanks. -- resolution: -> wont fix status: open -> closed ___ Python tracker ___

[issue28560] Implement `PurePath.startswith` and `PurePath.endswith`

2016-10-30 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: >>> from pathlib import Path >>> p = Path('/foo/bar') >>> Path('/foo') in p.parents True >>> Path('/spam') in p.parents False >>> p.parts[:2] == ('/', 'foo') True >>> p.parts[:2] == ('/', 'spam') False >>> p.relative_to('/foo') PosixPath('bar') >>>

[issue28560] Implement `PurePath.startswith` and `PurePath.endswith`

2016-10-30 Thread Ram Rachum
Ram Rachum added the comment: I mean that `/foo` is one of the parent directories. "there are plenty of options ..." Can you please spell them out precisely? The full line of code. -- ___ Python tracker

[issue28560] Implement `PurePath.startswith` and `PurePath.endswith`

2016-10-30 Thread SilentGhost
SilentGhost added the comment: Do you mean that /foo was just an arbitrary string, rather than one of the parent directories? Because in that case it seems a perfectly correct way to go about comparison. If /foo was one of the parents, there are plenty of options: .parts, .parents,

[issue28560] Implement `PurePath.startswith` and `PurePath.endswith`

2016-10-29 Thread Ram Rachum
New submission from Ram Rachum: Today I had to check whether a path object started with `/foo`. The nicest way I could think of was `str(p).startswith('/foo')`. What do you think about implementing `p.startswith('/foo')`? -- components: Library (Lib) messages: 279699 nosy: cool-RR,