On 10 April 2016 at 17:12, Greg Ewing <[email protected]> wrote:
> Nick Coghlan wrote:
>>
>> Similar to my proposal for dealing with DirEntry.path being a
>> bytes-like object, I'd like to suggest raising TypeError in __fspath__
>> if the request is nonsensical for the currently running system - *nix
>> systems can *manipulate* Windows paths (and vice-versa), but actually
>> trying to *use* them with the local filesystem isn't going to work
>> properly, since the syntax and semantics are different.
>
>
> That sounds reasonable, since it would be preferable to
> fail early if you mistakenly pass a PureWindowsPath to
> e.g. open().
>
> But there needs to be some way to ask a path object for
> its native string representation, otherwise there would
> be no point in using foreign path objects at all.
In addition to the existing "str(pathobj)", a "path" property was
recently added for that purpose:
>>> import pathlib
>>> pathlib.PureWindowsPath(".")
PureWindowsPath('.')
>>> pathlib.PureWindowsPath(".").path
'.'
(The specific property name was chosen to match os.scandir's DirEntry.path)
Cheers,
Nick.
--
Nick Coghlan | [email protected] | Brisbane, Australia
_______________________________________________
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com