Pathlib学习

Pathlib返回的路径是WindowsPath或PosixPath。这个取决于我们的操作系统 Pathlib会自动调整路径的格式,从而让我们的代码platform-independent。 获取当前路径 Path.cwd() 串联路径 无论使用什么操作系统,都使用forward-slash来串联路径 from pathlib import Path for the_file in Path.cwd().glob("*.pdf") new_path = Path("/data/archive") /the_file.name the_file.rename(new_path) 等效于.joinpath()函数 针对path对象的常见操作 1. .name 获取文件名,不包含路径 2. .stem 文件名称,…

Coming soon

This is Blog of Dr. Shaolin Xu, a brand new site by Shaolin Xu that's just getting started. Things will be up and running here shortly, but you can subscribe in the meantime if you'd like to stay up to date and receive emails when new…