【发布时间】:2015-06-25 14:13:25
【问题描述】:
我正在使用一些非常标准的代码:
1 if not os.path.exists(args.outputDirectory):
2 if not os.makedirs(args.outputDirectory, 0o666):
3 sys.exit('Fatal: output directory "' + args.outputDirectory + '" does not exist and cannot be created')
我删除了该目录,1 的支票直接转到2。我更进一步,并在3 发送错误消息。
但是,当我检查时,目录已成功创建。
drwxrwsr-x 2 userId userGroup 4096 Jun 25 16:07 output/
我错过了什么??
【问题讨论】:
-
旁白:使用
if os.path.isdir(...)可能比if os.path.exists(...)更好。如果预期的目录名称已作为常规文件存在,您的代码将产生意想不到的结果。
标签: python python-3.x mkdirs