主要介绍在平时遇到的os模块的使用方法;


1. os.path

1.1 os.path.sep

# 系统路径分隔符
# ================= # windows下
print(os.path.sep) # \ # ubuntu 16.04
print(os.path.sep) # /

1.2 os.path.join与os.path.sep.join

# 路径拼接
# ================= # windows下
print(os.path.join('dataset', 'images')) # dataset\images
print(os.path.sep.join(['dataset', 'images'])) # dataset\images # ubuntu 16.04
print(os.path.join('dataset', 'images')) # dataset/images
print(os.path.sep.join(['dataset', 'images'])) # dataset/images

2. os.work

# 使用如下:
# 文件结构如下:
"""
dataset\
chen\
img1.jpg
img2.jpg
zhen\
img3.jpg
img4.jpg
"""
# ================= path = 'dataset/'
for (rootdir, dirNames, filenames) in os.walk(path):
print(rootDir, dirNames, filenames)
dataset/ ['chen', 'zhen'] []
dataset/chen [] ['img1.jpg', 'img2.jpg']
dataset/zhen [] ['img3.jpg', 'img4.jpg']

最新文章

  1. POJ 2029 Get Many Persimmon Trees
  2. 通过printf设置Linux终端输出的颜色和显示方式
  3. ubuntu 快速安装jre
  4. 采用CSS3设计的登陆界面
  5. UDPsocket编程
  6. Android入门视频推荐
  7. 【转】Dr.com 5.20破解教程
  8. shell如何将文件上传至ftp
  9. JavaScript、jQuery获取页面及个元素高度、宽度
  10. Android EventBus源代码解析 带你深入理解EventBus
  11. Python 装饰器(Decorator)
  12. PMP是什么,PMP最难的是哪些内容?
  13. PHP实现微信模板消息发送给指定用户
  14. JS(JavaScript)的初了解6(更新中···)
  15. 编辑技巧之如何跟PDF文档添加贝茨编号
  16. python学习总结---学习交流群里的问题总结
  17. 参数优化-API
  18. MySQL--派生表Condition Pushdown优化
  19. 网页中flash设置
  20. keras中TimeDistributed

热门文章

  1. MySQL 当记录不存在时insert,当记录存在时update
  2. 2.4 AppDelegate 的 3 个生命周期
  3. CodeForces - 1017 C. The Phone Number(数学)
  4. bzoj 5120 无限之环 & 洛谷 P4003 —— 费用流(多路增广SPFA)
  5. JavaScript-Tool-富文本:UEditor
  6. bzoj2118
  7. python unittest之断言及示例
  8. linux命令-xz压缩
  9. com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; che
  10. ubuntu14.04装完系统更新后桌面挂了