windows путь пути не работает для pathlib в linux python? - PullRequest
1 голос
/ 18 марта 2020

В windows с pathlib.Path оба windows пути ароматизации и linux пути ароматизации работают нормально, но в linux кажется, что только linux путь ароматизации работает, это ожидаемо?

В windows:

  • и Path ("/ windows / Logs"), и Path (r "\ windows \ Logs") могут возвращать путь к Windows и могут нормально работать
Python 3.8.0 (tags/v3.8.0:fa919fd, Oct 14 2019, 19:37:50) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from pathlib import Path
>>> Path("\\windows\\Logs")
WindowsPath('/windows/Logs')
>>> Path("/windows/Logs")
WindowsPath('/windows/Logs')
>>> Path("\\windows\\Logs").exists()
True
>>> Path("/windows/Logs").exists()
True
>>> (Path("\\windows\\Logs")/"../Logs").resolve()
WindowsPath('C:/Windows/Logs')

В Linux:

  • Хотя возвращаются как Path ("/ usr / sr c"), так и Path (r "\ usr \ sr c") posixpath, но путь (r "\ usr \ sr c") не работает
Python 3.8.2 (default, Feb 26 2020, 14:58:38)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from pathlib import Path
>>> Path("/usr/src/app")
PosixPath('/usr/src/app')
>>> Path(r"\usr\src\app")
PosixPath('\\usr\\src\\app')
>>> Path("/usr/src/app").exists()
True
>>> Path(r"\usr\src\app").exists()
False
>>> (Path("/usr/src") / r"..\src\app").resolve()
PosixPath('/usr/src/..\\src\\app')
>>> (Path("/usr/src") / r"..\src\app").exists()
False
>>> (Path("/usr/src") / r"..\src\app").as_posix()
'/usr/src/..\\src\\app'
...