python标准库os库的函数介绍
作者:闫_锋 时间:2022-02-26 09:57:15
OS库提供通用的,基本的操作系统交互功能。
-OS库是Python标准库,包含几百个函数
-常用路径操作,进程管理,环境参数等几类
-路径操作: os.path子库,处理文件路径及信息
-进程管理:启动系统中其他程序
-环境参数:获得系统软硬件信息等环境参数
os.path子库以path为入口,用于操作和处理文件路径
import os.path
import os.path as op
os.path.abspath(path) #返回path在当前系统中的绝对路径
os.path.normpath(path) #归一化path的表示形式,统一用\\分隔路径
os.path.relpath(path) #返回当前程序与文件之间的相对路径
os.path.dirname(path) #返回path中的目录名称
os.path.basename(path) #返回path中最后的文件名称
os.path.join(path, *paths) #组合path与paths,返回一个路径字符串
os.path.exists(path) #判断path对应文件或目录是否存在,返回True或False
os.path.isfile(path)
os.path.isdir(path)
os.path.getatime(path) #返回path对应文件或目录上一次的访问时间
os.path.getmtime(path) #返回path对应文件或目录最近一次的修改时间
os.path.getctime(path) #返回path对应文件或目录最近一次的修改时间
os.path.getsize(path) #返回path对应文件的大小,以字节为单位
python os库进程管理
使用当前python程序调用外部程序
os.system(command)
在操作系统中执行command
返回command程序执行之后的返回值
import os
#os.system(command)
os.system("C:\\Windows\\System32\\calc.exe")
os.system("C:\\Windows\\System32\\mspaint.exe" \
D:\\PYECourse\\grwordcloud.png)
python 获取或改变系统环境信息
os.chdir(path) #修改当前程序的操作路径
os.getcwd() #返回程序的当前路径
os.getlogin() #获得当前系统登录用户名称
os.cpu_count() #获得当前系统的CPU数量
来源:https://www.jianshu.com/p/2b12a065ea22
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
详解Python_shutil模块
无组件上传图片到数据库中,asp解决方案
ASP把数字用逗号每3位隔开显示代码
![](https://img.aspxhome.com/file/UploadPic/20081/2/200812132551808s.gif)
Httprunner简介、安装及基本使用教程
![](https://img.aspxhome.com/file/2023/0/110260_0s.png)
发一段鼠标掠过表格行颜色改变的代码
Python 绘制酷炫的三维图步骤详解
![](https://img.aspxhome.com/file/2023/7/75217_0s.jpg)
Python数据可视化之Seaborn的使用详解
![](https://img.aspxhome.com/file/2023/2/89292_0s.png)
Python二进制文件读取并转换为浮点数详解
![](https://img.aspxhome.com/file/2023/0/77640_0s.png)
Python实现的桶排序算法示例
![](https://img.aspxhome.com/file/2023/4/110364_0s.png)
Python实现的计算器功能示例
![](https://img.aspxhome.com/file/2023/1/81681_0s.gif)
详解在Python程序中自定义异常的方法
ExecuteReader(),ExecuteNonQuery(),ExecuteScalar(),ExecuteXmlReader()之间的区别
python中random模块详解
![](https://img.aspxhome.com/file/2023/1/61211_0s.png)
深入解析Python编程中super关键字的用法
如何绕过ODBC直接访问SQL Server?
Pygame Surface创建图像的实现
pandas中的DataFrame数据遍历解读
![](https://img.aspxhome.com/file/2023/7/93457_0s.png)
Golang详细讲解常用Http库及Gin框架的应用
简单说明Python中的装饰器的用法
![](https://img.aspxhome.com/file/2023/8/89428_0s.png)