Python模块简介--os模块
2018-01-18 14:56
225 查看
一、模块简介
Python os模块包含普遍的操作系统功能,让你的程序和平台分开。通常用于返回和打开指定目录下的所有文件和目录名。
二、常用函数
1、os.listdir(path) —– 返回指定目录下的所有文件和目录名
2、os.path.join(path,name) —- 链接目录和文件名
3、os.path.exists() —- 函数用来检验给出的路径是否真地存在
4、os.makedirs() —- 用于创建目录
Python os模块包含普遍的操作系统功能,让你的程序和平台分开。通常用于返回和打开指定目录下的所有文件和目录名。
二、常用函数
1、os.listdir(path) —– 返回指定目录下的所有文件和目录名
folder = 'rt_html' for movie_html in os.listdir(folder)
os.listdir(folder_name)---返回路径下的文件名
2、os.path.join(path,name) —- 链接目录和文件名
folder = 'rt_html' for movie_html in os.listdir(folder):
with open (os.path.join(folder,movie_html)) as file:
3、os.path.exists() —- 函数用来检验给出的路径是否真地存在
os.path.exists(‘C:\Python25\abc.txt’) False os.path.exists(‘C:\Python25’) True
4、os.makedirs() —- 用于创建目录
folder_name = 'ebert_reviews' if not os.path.exists(folder_name): os.makedirs(folder_name)
相关文章推荐
- Python中的OS模块简介
- Python的os模块简介
- Python笔记(5):sys模块,os模块,set,heap,deque简介
- Python os模块简介
- python~module gzip 使用方法,及简介! 附件 python ~ os 模块!!!
- python中os.path以及sys.path模块简介
- python os模块简介
- python中os.path以及sys.path模块简介
- Python模块: 文件和目录os+shutil
- python logging模块简介
- Python学习笔记之os模块
- Python系统操作(sys、os)模块
- python os.path模块常用方法
- Python os.path模块
- Python--os模块--shutil
- Python OS模块总结
- Python sys&os模块
- python常用的一些东西——sys、os模块
- Python中os和shutil模块实用方法集锦
- python3 os模块文件、目录常用函数方法总结