List from CSV is empty

173
1
02-05-2021 05:29 AM
CliveSwan
Occasional Contributor II

Greetings,

I am trying to read in a list from a csv file, using that to select Features within SDE.

The list is empty??

The csv file is:

 

 

server.gis.BreedingBirdSurvey_Tbl,
server.gis.Heronries_Tbl,
server.gis.Invertebrates_Pt,
server.gis.Vertebrates_Pt,
server.gis.FreshwaterFishCounts_Pt,
server.gis.InvasiveNonNativeSpecies_Pt,
server.gis.MacroinvertebrateSurvey_Pt,
server.gis.MacrophyteSurvey_Pt,
server.gis.PriorityHabitat_Pt,
server.gis.RiverHabitatSurveys_Pt,
server.gis.NonNative_Pt,
server.gis.RareProtectedSpecies_Pt

 

 

 

The code is:

 

 

#### Features
fcs = arcpy.ListFeatureClasses("server.gis.*")

#### CSV file
asc_f = r"W:\My Documents\user\AS_1.csv"

print("LOOP")
with open(asc_f, mode='r') as csv_file:
    csv_reader = csv.DictReader(csv_file)
    for row in csv_reader:
        #print(row)               

        for fc in fcs:
            if fc == row:
                new_name = fc.split(".")[-1]
                #print(fc)
                print(row)
                #arcpy.FeatureClassToFeatureClass_conversion(fc, outLocation, new_name)
            else:
                print("NOT in list")

############                               
print("END")

 

 

 

 

 

From 
print("LOOP")
with open(asc1_f, mode='r') as csv_file:
    csv_reader = csv.DictReader(csv_file)
    for row in csv_reader:
        print(row) 

This returns:
START
LOOP
OrderedDict([('server.gis.BreedingBirdSurvey_Tbl', 'server.gis.Heronries_Tbl')])
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
OrderedDict([('server.gis.BreedingBirdSurvey_Tbl', 'server.gis.Invertebrates_Pt')])
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
OrderedDict([('server.gis.BreedingBirdSurvey_Tbl', 'server.gis.Vertebrates_Pt')])
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
OrderedDict([('server.gis.BreedingBirdSurvey_Tbl', 'server.gis.FreshwaterFishCounts_Pt')])
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
OrderedDict([('server.gis.BreedingBirdSurvey_Tbl', 'server.gis.invertebrateSurvey_Pt')])
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
OrderedDict([('server.gis.BreedingBirdSurvey_Tbl', 'server.gis.MacrophyteSurvey_Pt')])
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list

 

 

 

 

 

 

It returns:
START
LOOP
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list
NOT in list

 

 

 

 

 

 

I expected:
'server.gis.BreedingBirdSurvey_Tbl', 
'server.gis.Heronries_Tbl'
'server.gis.Invertebrates_Pt'
'server.gis.Vertebrates_Pt'
'server.gis.MacrophyteSurvey_Pt'
'server.gis.Ancient_Woodland'
'server.gis.Sites_Special_Scientific_Interest'
'server.gis.Sites_Special_Scientific_Interest_GRP'
'server.gis.Special_Protection_Areas'


OR
"server.gis.BreedingBirdSurvey_Tbl" 
"server.gis.Heronries_Tbl"
"server.gis.Invertebrates_Pt"
"server.gis.Vertebrates_Pt"
"server.gis.MacrophyteSurvey_Pt"
"server.gis.Ancient_Woodland"
"server.gis.Sites_Special_Scientific_Interest"
"server.gis.Sites_Special_Scientific_Interest_GRP"
"server.gis.Special_Protection_Areas"

 

 

 

I would appreciate any pointers

Tags (3)
0 Kudos
1 Reply
JeffK
by
Occasional Contributor III

the DictReader returns a dictionary and I don't see where you are parsing the value to check against your fc name list.  Print the row from the csv cursor to see what format it is in.

 

Or just use csv.reader(csv_file) if you don't need a dictionary of values, which I don't think you need for this.