os.path.isfile

Chris Angelico rosuav at gmail.com
Sat Feb 11 23:29:20 EST 2017


On Sun, Feb 12, 2017 at 3:20 PM, eryk sun <eryksun at gmail.com> wrote:
> On Sun, Feb 12, 2017 at 3:52 AM, Steve D'Aprano
> <steve+python at pearwood.info> wrote:
>> In Python, you should always use forward slashes for paths, even on Windows.
>
> There are cases where slash doesn't work (e.g. some command lines;
> \\?\ prefixed paths; registry subkey paths), so it's simpler to follow
> a rule to always convert paths to backslash on Windows, using
> os.path.normpath or pathlib.Path.

Registry subkeys aren't paths, and the other two cases are extremely
narrow. Convert slashes to backslashes ONLY in the cases where you
actually need to.

ChrisA



More information about the Python-list mailing list