3
通过自动完成发现一个pathlib.Path
第一种方法是absolute()
。我可以使用无证方法pathlib.Path.absolute()?
似乎在一开始只是在前面加上Path.cwd():
>>> from pathlib import Path
>>> path = Path('./relative/path')/'../with/some/../relative/parts'
Path('relative/path/../with/some/../relative/parts')
# calling absolute...
>>> absolute_path = path.absolute()
Path('/[current_dir]/relative/path/../with/some/../relative/parts')
# does the same as prepending cwd at the start
>>> Path.cwd()/path
Path('/[current_dir]/relative/path/../with/some/../relative/parts')
然而,Path.absolute()
没有在pathlib documentation上市。
比较这对Path.resolve(),它执行相反的(取代的相对的部分,但不预置cwd
)和是记载。
我可以用absolute()
或者我应该避免呢?