python:: os.path vs path from pathlib

 

Not all pairs of functions/methods below are equivalent. Some of them, despite having some overlapping use-cases, have different semantics. They include os.path.abspath() and Path.absolute(), os.path.relpath() and PurePath.relative_to().

os and os.pathpathlib
os.path.abspath() Path.absolute()
os.path.realpath() Path.resolve()
os.chmod() Path.chmod()
os.mkdir() Path.mkdir()
os.makedirs() Path.mkdir()
os.rename() Path.rename()
os.replace() Path.replace()
os.rmdir() Path.rmdir()
os.remove(), os.unlink() Path.unlink()
os.getcwd() Path.cwd()
os.path.exists() Path.exists()
os.path.expanduser() Path.expanduser() Path.home()
os.listdir() Path.iterdir()
os.path.isdir() Path.is_dir()
os.path.isfile() Path.is_file()
os.path.islink() Path.is_symlink()
os.link() Path.hardlink_to()
os.symlink() Path.symlink_to()
os.readlink() Path.readlink()
os.path.relpath() PurePath.relative_to() 2
os.stat() Path.stat(), Path.owner(), Path.group()
os.path.isabs() PurePath.is_absolute()
os.path.join() PurePath.joinpath()
os.path.basename() PurePath.name
os.path.dirname() PurePath.parent
os.path.samefile() Path.samefile()
os.path.splitext() PurePath.stem and PurePath.suffix

 

 

 

https://docs.python.org/ko/3/library/pathlib.html#pathlib.PurePath.stem

 

pathlib — Object-oriented filesystem paths

Source code: Lib/pathlib.py This module offers classes representing filesystem paths with semantics appropriate for different operating systems. Path classes are divided between pure paths, which p...

docs.python.org

 

 

 

 

 


https://engineer-mole.tistory.com/191

 

[python] pathlib 사용법 (패스(경로)를 객체로써 조작, 처리)

Python의 pathlib모듈을 사용하면, 파일, 디렉토리(폴더)의 경로를 객체로써 조작하거나 처리할 수 있다. 파일명 혹은 부모 디렉토리를 알아내거나, 경로의 목록을 얻어내거나, 파일을 작성하거나

engineer-mole.tistory.com

 

 

_

반응형