Pylint在我打电话函数deletdcmfiles()
的最后一行上投诉。Final newline missing
。我是Python的新手,我不确定是什么触发了?
这是程序的代码:
'''
This program will go through all Work subdirectorys in "D:\Archvies" folder
and delete all DCM files older then three months.
'''
import os.path
import glob
import time
#Create a list of Work directorys in Archive folder
WORKDIR = glob.glob("D:\Archives\ASP*\Work*")
#Variable holds three months of time in seconds
THREEMONTHSOLD = (time.time()) - (90 * 86400)
def deletdcmfiles():
'''
This function will go through all Work subdirectorys in "D:\Archvies" folder
and delete all DCM files older then three months.
'''
#Variable to keep counter of deleted files
deleted_files = 0
#Loop through each Work subdirectory and delete all .DCM files older then 3 months
for mydir in enumerate(WORKDIR):
#Store all directory files in a list
dcmfiles = glob.glob(mydir[1] + "\" + "*.dcm")
#Compare Modified Date of each DCM file and delete if older then 3 Months
for file in enumerate(dcmfiles):
if os.path.getmtime(file[1]) < THREEMONTHSOLD:
print("Deleted " + file[1] + " " + time.ctime(os.path.getmtime(file[1])))
os.remove(file[1])
deleted_files += 1
print("Total Files Deleted :" + str(deleted_files))
#Run program
deletdcmfiles()
您在文件末尾需要一个空的新线路。只需在最后一行的末尾添加另一个 Enter 就可以了。
我只是遇到了这个问题,并找到了一个类似问题的答案:
您至少需要一个新线的原因是历史上有些如果文件结束和最后一行的文本,工具会出现问题但在文件末尾没有新线。写得不好工具可能会错过处理最后一行的处理,甚至更糟的是在最后一行之外读取随机内存(尽管不太可能用python编写的工具发生,可以用编写的工具发生在c(。
因此,您必须确保有一个纽线,以终止最后一个非空白线。
我在下面有相同的错误:
最终的newline缺少佩林(C0304:缺失 - 本文(
因为我没有在上一个代码print(math.pi)
之后添加一条空白行,如下所示:
1 import math
2
3 print(math.pi)
所以,我在最后一个代码print(math.pi)
之后添加了一条空白行,如下所示,该错误已解决:
1 import math
2
3 print(math.pi)
4
此外,如果您在最后一个代码之后添加多个空白行,如下所示:
1 import math
2
3 print(math.pi)
4
5
然后,您在下面收到错误:
落后于newlinespylint(c0305:trafing newlines(