标签:style pre empty module call spl ast python2.7 方法
只能删除空文件夹,删除非空文件夹会报错
>>> import os >>> os.rmdir("/tmp/ssh-GyoPWOFZ47") Traceback (most recent call last): File "<stdin>", line 1, in <module> OSError: [Errno 39] Directory not empty: ‘/tmp/ssh-GyoPWOFZ47‘
>>> os.removedirs("/tmp/ssh-GyoPWOFZ47") Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python2.7/os.py", line 170, in removedirs rmdir(name) OSError: [Errno 39] Directory not empty: ‘/tmp/ssh-GyoPWOFZ47‘
经测试下面的方法,可以删除非空文件夹
>>> import shutil >>> shutil.rmtree("/tmp/ssh-GyoPWOFZ47") >>> >>> exit()
这里只删除了 ssh-GyoPWOFZ47 文件夹
标签:style pre empty module call spl ast python2.7 方法
原文地址:https://www.cnblogs.com/sea-stream/p/10337324.html