os模块操作文件

os模块:

path=os.path.join(os.path.dirname(os.path.dirname(__file__)),'images')

path:运行脚本的当前文件下的上一个文件的地址+images

os.path.dirname(__file__)

脚本是以完整路径被运行的, 那么将输出该脚本所在的完整路径,比如:

python d:/pythonSrc/test/test.py

那么将输出 d:/pythonSrc/test


脚本是以相对路径被运行的, 那么将输出空目录,比如:

python test.py

那么将输出空字符串

 

将path的地址添加上‘image’

os.path.join(path,‘image’) 


判断是否有path文件夹

os.path.exists(path)

 

创建一个文件夹

os.mkdir(self.path)

 

posted @ 2019-04-11 20:24  LuoSpider  阅读(219)  评论(0编辑  收藏  举报