首页 > 其他 > 详细

偶见错误异常01

时间:2021-05-08 09:55:03      阅读:14      评论:0      收藏:0      [点我收藏+]
import os
L=[]
def delete_file(file):
if os.path.isdir(file):
    files=os.listdir(file)
    for x in files:
        x=os.path.join(file,x)
        if os.path.isfile(x):
            print( os.path.split(x)[1])
            L.append(os.path.split(x)[1])
            # os.remove(x)
        elif os.path.isdir(x) :
            print(os.path.split(x)[1])
            L.append(os.path.split(x)[1])
            # if len(os.listdir(x))!=0:
            delete_file(x)
else:
    L.append(os.path.split(file))

ll=delete_file(r‘E:\\ALL_IN\python脚本\a‘)
print(‘-------------------‘)
print(L)
  • 执行程序的时候一直有一个返回值None,起初还以为列表中没有元素,之后反省过来,ll是为空的,因为delete_file()函数没有返回值,所以ll==None,
  • 只是把得出结果放在L中了,用一个全局变量装载了元素。程序执行的打印输出正确,最后得出的结果正确,程序没有问题。。。

偶见错误异常01

原文:https://www.cnblogs.com/shiyishou/p/14743322.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!