2012-01-08 102 views
0

请在下面找到我的Python脚本创建目录内的目录:使用Python脚本语言

import os; 
import sys; 

dir_dst = sys.argv[1] 

for x in range(150) : 
    dirname = str(x) 
    dst_dir = os.path.join(dir_dst, dirname) 
    dirname = "annotation" 
    dst = os.path.join(dst_dir, dirname) 
    print dst 
    if not os.path.exists(dst_dir): 
     os.mkdir(dst) 

目的是创建一个名为“注释”中的每个编号的目录范围如上代码的目录。此代码不能做到这一点,上打印“夏令时”的值,下面是它给出了一个例子:

NLP/test data/reconcile/0\annotation 
NLP/test data/reconcile/1\annotation 

这又如何解决?

+0

无需使用';'后面的'import'语句 – juliomalegria 2012-01-08 22:45:38

+0

感谢您的输入 – 2012-01-08 23:04:14

回答

4

更改倒数第二行以

if not os.path.exists(dst): 

现在你检查,如果原来的目录存在。

+0

oops!它解决了它......谢谢。 – 2012-01-08 22:49:04

+2

不要忘记接受:) – 2012-01-08 22:49:51

+0

是的,先生.... :) – 2012-01-08 23:03:54