这是我在python中用来删除旧目录的函数
def delete_olddirs(days,file_path):
numdays = 60*60*24*days
now = time.time()
for dir in os.listdir(file_path):
r = file_path
timestamp = os.path.getmtime(os.path.join(r,dir))
if now-numdays > timestamp:
try:
print "removing ",os.path.join(r,dir)
#shutil.rmtree(os.path.join(r,dir)) #uncomment to use
except Exception,e:
print e
pass
else:
print "some message for success"
问题是每次我看到消息removing . ....
我也会看到消息
some message for success
我想知道为什么每次都要执行else部分
如果没有引发异常,则执行
else
的try
部分。你知道吗http://docs.python.org/reference/compound_stmts.html#the-try-statement
似乎很清楚。你知道吗
另外一点是成功,你误解了它的目的。 见:http://docs.python.org/tutorial/errors.html
相关问题 更多 >
编程相关推荐