os.path vs pathlib

os.path

当年使用的这些方法如今还记忆尤新。
os.path.join()
os.path.dirname()
os.path.abspath()

pathlib

注意:python3.4+
pathlib是什么?我的理解就是一种优雅的路径地址访问方式,基于类使用。
Object-oriented filesystem paths
主要是Path类,使用Path非常简单统一。

>>> from pathlib import Path

对照表

os and os.path

pathlib

os.path.abspath()

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() and 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.link_to()

os.symlink()

Path.symlink_to()

os.readlink()

Path.readlink()

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.suffix


vscode and python
最近发现一个可怕的事情,那就是vscode里面写python竟然特别的流畅,vscode真是一个不错的编辑器(当然仅仅是我自己觉得)。


分享一张好图,后面介绍
迭代器
可迭代的
生成器
列表
在这里插入图片描述

posted @ 2022-03-06 10:37  叶常落  阅读(18)  评论(0编辑  收藏  举报