[issue46362] os.path.abspath() needs more normalization on Windows

neonene report at bugs.python.org
Thu Jan 13 08:30:57 EST 2022


neonene <nicesalmon at gmail.com> added the comment:

Basically, PR30571 aims for compatibility with 3.10 and earlier. Using Windows API is the easiest and the same way as them:

import os.path
paths = [
    r'C:\CON',
    r'C:\PRN',
    r'C:\AUX',
    r'C:\NUL',
    r'C:\COM1',
    r'C:\COM2',
    r'C:\COM3',
    r'C:\COM9',
    r'C:\LPT1',
    r'C:\LPT2',
    r'C:\LPT3',
    r'C:\LPT9',
    r'C:\foo. . .',
]
for path in paths:
    print(os.path.abspath(path))

"""
3.11 before
    C:\CON
    C:\PRN
    C:\AUX
    C:\NUL
    C:\COM1
    C:\COM2
    C:\COM3
    C:\COM9
    C:\LPT1
    C:\LPT2
    C:\LPT3
    C:\LPT9
    C:\foo. . .

3.11 after
    \\.\CON
    \\.\PRN
    \\.\AUX
    \\.\NUL
    \\.\COM1
    \\.\COM2
    \\.\COM3
    \\.\COM9
    \\.\LPT1
    \\.\LPT2
    \\.\LPT3
    \\.\LPT9
    C:\foo

3.10.1
    \\.\CON
    \\.\PRN
    \\.\AUX
    \\.\NUL
    \\.\COM1
    \\.\COM2
    \\.\COM3
    \\.\COM9
    \\.\LPT1
    \\.\LPT2
    \\.\LPT3
    \\.\LPT9
    C:\foo
"""

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue46362>
_______________________________________


More information about the Python-bugs-list mailing list