2017-06-01 30 views
7

Pylint抱怨最后一行,我调用函数“deletdcmfiles()”。 “最终换行符失踪”。我是新来的python,我不知道什么是触发这个?Pylint给我“最后的新行缺失”

下面是该程序的代码:

''' 
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() 
+1

它期望文件末尾有一个额外的换行符。它与文件中包含的Python代码没有任何关系。 – mkrieger1

+0

谢谢你解决它。 –

回答

9

你在你的文件的结尾需要一个新的空行。只需在最后一行的末尾添加另一个ENTER,您就会安然无恙。

+1

谢谢你,这个伎俩。 :) –