Pathlib объединяет абсолютный путьPython

Программы на Python
Гость
Pathlib объединяет абсолютный путь

Сообщение Гость »


Я пытаюсь соединить два пути, второй начинается с косой черты.

Код: Выделить всё

from pathlib  import Path

path = Path('/first', '/second')

# outputs WindowsPath('/second')
# expecting WindowsPath('/first/second')
print(path)
From the example above, you can see it removes the first path.
While it's not a big deal to use something like removeprefix('/'), I'm curious to know why it's behaving this way. Is there is a builtin way to change this behaviour?


Источник: https://stackoverflow.com/questions/772 ... h-together

Вернуться в «Python»