检查空白行

2019-07-17  本文已影响0人  峤桓
import os, arcpy
arcpy.env.workspace = r"C:\Users\Administrator\Desktop\s\in"
fes = arcpy.ListFeatureClasses()
fieldA = "TYID"
fieldB = "YEAR"
fieldC = "NCHN"
error = "have error"
for fe in fes:
    cursor = arcpy.SearchCursor(fe)
    for row in cursor:
        tyid = row.getValue(fieldA)
        if tyid== 0:
            print (fe.split(".")[0]+" TYID "+error)
        year = row.getValue(fieldB)
        if year == " ":
            print (fe.split(".")[0]+" YEAR "+error)
        nchn = row.getValue(fieldC)
        if nchn == " ":
            print (fe.split(".")[0]+" NCHN "+error)

with open(files,"wb") as csvfile: 
    writer = csv.writer(csvfile)
    writer.writerow(["name","count"])
    writer.writerows(shpdata)
    writer.writerow(["Allshp",all])
import os, arcpy,csv
arcpy.env.workspace = r"C:\Users\Administrator\Desktop\s\in"
fsave = r"C:\Users\Administrator\Desktop\s\excel"
files = fsave+'/CheckNullerror.csv'

fes = arcpy.ListFeatureClasses()
for fe in fes:
    CONIDcount = 0
    cursorCONID = arcpy.da.SearchCursor(fe,("CONID","NCHN","NENG","TYID","YEAR","REFER","PERIOD"))    
    for row in cursorCONID:
        if row[0] == 0 or row[0] == None :           
                CONIDcount = CONIDcount +1  
    CONIDResult = fe.split(".")[0]+" CONID error",(CONIDcount)
    if CONIDcount == 0 :
        print (fe.split(".")[0] +" CONID OK")
    if CONIDcount != 0 :
        print (CONIDResult)

    NCHNcount = 0
    cursorNCHN = arcpy.da.SearchCursor(fe,("NCHN"))    
    for row in cursorNCHN:
        if row[0] == " " or row[0] == None :           
                NCHNcount = NCHNcount +1  
    NCHNResult = fe.split(".")[0]+" NCHN error ",(NCHNcount)
    if NCHNcount == 0 :
        print (fe.split(".")[0] +" NCHN OK")
    if NCHNcount != 0 :
        print (NCHNResult)

    NENGcount = 0
    cursorNENG = arcpy.da.SearchCursor(fe,("NENG"))    
    for row in cursorNENG:
        if row[0] == " " or row[0] == None :           
                NENGcount = NENGcount +1  
    NENGResult = fe.split(".")[0]+" NENG error ",(NENGcount)
    if NENGcount == 0 :
        print (fe.split(".")[0] +" NENG OK")
    if NENGcount != 0 :
        print (NENGResult)

    TYIDcount = 0
    cursorTYID = arcpy.da.SearchCursor(fe,("TYID"))    
    for row in cursorTYID:
        if row[0] == 0 or row[0] == None :           
                TYIDcount = TYIDcount +1  
    TYIDResult = fe.split(".")[0]+" TYID error ",(TYIDcount)
    if TYIDcount == 0 :
        print (fe.split(".")[0] +" TYID OK")
    if TYIDcount != 0 :
        print (TYIDResult)

    YEARcount = 0
    cursorYEAR = arcpy.da.SearchCursor(fe,("YEAR"))    
    for row in cursorYEAR:
        if row[0] == " " or row[0] == None :           
                YEARcount = YEARcount +1  
    YEARResult = fe.split(".")[0]+" YEAR error ",(YEARcount)
    if YEARcount == 0 :
        print (fe.split(".")[0] +" YEAR OK")
    if YEARcount != 0 :
        print (YEARResult)

    REFERcount = 0
    cursorREFER = arcpy.da.SearchCursor(fe,("REFER"))    
    for row in cursorREFER:
        if row[0] == " " or row[0] == None :           
                REFERcount = REFERcount +1  
    REFERResult = fe.split(".")[0]+" REFER error ",(REFERcount)
    if REFERcount == 0 :
        print (fe.split(".")[0] +" REFER OK")
    if REFERcount != 0 :
        print (REFERResult)

    PERIODcount = 0
    cursorPERIOD = arcpy.da.SearchCursor(fe,("PERIOD"))    
    for row in cursorPERIOD:
        if row[0] == " " or row[0] == None :   
                PERIODcount = PERIODcount +1    
    PERIODResult = fe.split(".")[0]+" PERIOD error ",(PERIODcount)
    if PERIODcount == 0 :
        print (fe.split(".")[0] +" PERIOD OK")
    if PERIODcount != 0 :
        print (PERIODResult)
        
with open(files,"wb") as csvfile: 
    writer = csv.writer(csvfile)
    writer.writerow(["name"])
    writer.writerows(CONIDResult)
    writer.writerows(NCHNResult)
    writer.writerows(NENGResult)
    writer.writerows(TYIDResult)
    writer.writerows(YEARResult)
    writer.writerows(REFERResult)
    writer.writerows(PERIODResult)
上一篇下一篇

猜你喜欢

热点阅读