New submission from Mond Wan <victor2...@gmail.com>:
I have tried 2 functions with different behavior across platform # as_posix() In linux platform, as_posix() cannot process window path nicely * From linux + docker + python:3.8 ``` Python 3.8.0 (default, Oct 17 2019, 05:36:36) [GCC 8.3.0] on linux >>> winPath = r'\workspace\xxx\test_fixture\user-restore-success.zip' >>> posixPath = '/workspace/xxx/test_fixture/user-restore-success.zip' >>> pWIN = pathlib.PurePath(winPath) >>> pPOSIX = pathlib.PurePath(posixPath) >>> pWIN.as_posix() '\\workspace\\xxx\\test_fixture\\user-restore-success.zip' >>> pPOSIX.as_posix() '/workspace/xxx/test_fixture/user-restore-success.zip' ``` * From window + powershell + python3.6 ``` Python 3.6.8 (tags/v3.6.8:3c6b436a57, Dec 24 2018, 00:16:47) [MSC v.1916 64 bit (AMD64)] on win32 >>> winPath = r'\workspace\xxx\test_fixture\user-restore-success.zip' >>> posixPath = '/workspace/xxx/test_fixture/user-restore-success.zip' >>> pWIN = pathlib.PurePath(winPath) >>> pPOSIX = pathlib.PurePath(posixPath) >>> pWIN.as_posix() '/workspace/xxx/test_fixture/user-restore-success.zip' >>> pPOSIX.as_posix() '/workspace/xxx/test_fixture/user-restore-success.zip' ``` * From MAC ``` >>> winPath = '\\workspace\\xxx\\test_fixture\\user-restore-success.zip' >>> posixPath = '/workspace/xxx/test_fixture/user-restore-success.zip' >>> pWIN = pathlib.PurePath(winPath) >>> pPOSIX = pathlib.PurePath(posixPath) >>> pWIN.as_posix() '\\workspace\\xxx\\test_fixture\\user-restore-success.zip' >>> pPOSIX.as_posix() '/workspace/xxx/test_fixture/user-restore-success.zip' ``` # resolve() In window platform, resolve() returns absolute path only if such file is able to locate. Otherwise, it returns relative path. In Linux platform, resolve() returns absolute path anyway * From linux ``` root@b4f03ed3003b:/var/run/lock# python Python 3.8.0 (default, Oct 17 2019, 05:36:36) [GCC 8.3.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import pathlib >>> p = pathlib.Path('no_exists') >>> p.resolve() PosixPath('/run/lock/no_exists') >>> str(p.resolve()) '/run/lock/no_exits' ``` * From window ``` Python 3.6.8 (tags/v3.6.8:3c6b436a57, Dec 24 2018, 00:16:47) [MSC v.1916 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import pathlib >>> p = pathlib.Path('README.md') >>> p.resolve() WindowsPath('C:/Users/xxx/PycharmProjects/yyy/README.md') >>> str(p.resolve()) 'C:\\Users\\xxx\\PycharmProjects\\yyy\\README.md' >>> p = pathlib.Path('no_exists') >>> p.resolve() WindowsPath('no_exists') >>> str(p.resolve()) 'no_exists' ``` Also, I have spotted a ticket similar to this one https://bugs.python.org/issue41357 ---------- components: FreeBSD, Windows, macOS messages: 374632 nosy: Mond Wan, koobs, ned.deily, paul.moore, ronaldoussoren, steve.dower, tim.golden, zach.ware priority: normal severity: normal status: open title: pathlib behave differ between OS versions: Python 3.6, Python 3.7, Python 3.8 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue41448> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com