Skip to main content
naming; formatting
Source Link
Vince
  • 20.3k
  • 16
  • 48
  • 65

I used a SearchCursor Objectobject to create a List ,list containing file paths, and saved the list to a variable called FilePathListFilePathList.

Next, I iterateiterated through elements within the list using a forfor loop. Within the forfor loop, I nested an ifif statement that contains the arcpy.Existarcpy.Exists function. I am inserting elements from the FilePathListFilePathList into the arcpy.existarcpy.Exists function. When list elements are inserted into the function;function, if the element exists a data object string “1” is created. In addition, if the element does not exist a data object string "0" is created. I read that the arcpy.Exists()arcpy.Exists() function returns a Boolean indicating whether the element exists.

I want to use the arcpy.Existsarcpy.Exists function to create string objects "1" representing exists and "0" representing does not exist. In the code below, I am able to print the string objects one by one,in in the correct order, to the console. However, I would like to append the strings to an empty list in the order that they are printed. The order is important because I will eventually insert the created list into a new field within the dbf file. The field needs to be in the correct order because it corresponds and links to another field.

import arcpy

arcpy.env.workspace = r"C:\TestFolder"

#dbf table used for processing
dbf = "C:\\TestFolder\\ProcessControlTable.dbf"
#Column within dbf table containing file paths 
myColumn = "FI_PATH"
#Temp list created to hold appended items from arcpy.Exists Function
Temp = []

#SearchCursorList created by using SearchCursorObject to create List 
FilePathList =[row[0] for row in arcpy.da.SearchCursor(dbf,myColumn)]
print(FilePathList)
for elements in FilePathList:
    if arcpy.Exists(elements):
        #If element in SearchCursorList Exists;
        #Define a variable called Exists and string object
        Exists = "1"
        Temp.append(Exists[0])
        print(Exists)

    else:
        DoesNotExist = "0"
        Temp.append(Exists[0])
        print(DoesNotExist)
        
print (Temp)

The output in the pythonPython shell first prints the list containing file paths. Next, strings created from looping with the arcpy.Existsarcpy.Exists function are printed one by one in the correct order. Lastly, the Temp ListTemp list is printed however all items in the list are the string object '1'. I want Temp ListTemp list to contain strings created from the arcpy.Existarcpy.Exists function looping in the correct order. The tempTemp list should print ['1','1','0','1','1','1','1','1','1','0']

Python Shell Output

ImI'm not sure what code will pull objects out of the loop and put it into a new list. I can't think of the logic with my limited pythonPython and arcpyArcPy knowledge.

I used a SearchCursor Object to create a List ,containing file paths, and saved the list to a variable called FilePathList.

Next, I iterate through elements within the list using a for loop. Within the for loop, I nested an if statement that contains the arcpy.Exist function. I am inserting elements from the FilePathList into the arcpy.exist function. When list elements are inserted into the function; if the element exists a data object string “1” is created. In addition, if the element does not exist a data object string "0" is created. I read that the arcpy.Exists() function returns a Boolean indicating whether the element exists.

I want to use the arcpy.Exists function to create string objects "1" representing exists and "0" representing does not exist. In the code below, I am able to print the string objects one by one,in the correct order, to the console. However, I would like to append the strings to an empty list in the order that they are printed. The order is important because I will eventually insert the created list into a new field within the dbf file. The field needs to be in the correct order because it corresponds and links to another field.

import arcpy

arcpy.env.workspace = r"C:\TestFolder"

#dbf table used for processing
dbf = "C:\\TestFolder\\ProcessControlTable.dbf"
#Column within dbf table containing file paths 
myColumn = "FI_PATH"
#Temp list created to hold appended items from arcpy.Exists Function
Temp = []

#SearchCursorList created by using SearchCursorObject to create List 
FilePathList =[row[0] for row in arcpy.da.SearchCursor(dbf,myColumn)]
print(FilePathList)
for elements in FilePathList:
    if arcpy.Exists(elements):
        #If element in SearchCursorList Exists;
        #Define a variable called Exists and string object
        Exists = "1"
        Temp.append(Exists[0])
        print(Exists)

    else:
        DoesNotExist = "0"
        Temp.append(Exists[0])
        print(DoesNotExist)
        
print (Temp)

The output in the python shell first prints the list containing file paths. Next, strings created from looping with the arcpy.Exists function are printed one by one in the correct order. Lastly, the Temp List is printed however all items in the list are the string object '1'. I want Temp List to contain strings created from the arcpy.Exist function looping in the correct order. The temp list should print ['1','1','0','1','1','1','1','1','1','0']

Python Shell Output

Im not sure what code will pull objects out of the loop and put it into a new list. I can't think of the logic with my limited python and arcpy knowledge.

I used a SearchCursor object to create a list containing file paths and saved the list to a variable called FilePathList.

Next, I iterated through elements within the list using a for loop. Within the for loop, I nested an if statement that contains the arcpy.Exists function. I am inserting elements from the FilePathList into the arcpy.Exists function. When list elements are inserted into the function, if the element exists a data object string “1” is created. In addition, if the element does not exist a data object string "0" is created. I read that the arcpy.Exists() function returns a Boolean indicating whether the element exists.

I want to use the arcpy.Exists function to create string objects "1" representing exists and "0" representing does not exist. In the code below, I am able to print the string objects one by one, in the correct order, to the console. However, I would like to append the strings to an empty list in the order that they are printed. The order is important because I will eventually insert the created list into a new field within the dbf file. The field needs to be in the correct order because it corresponds and links to another field.

import arcpy

arcpy.env.workspace = r"C:\TestFolder"

#dbf table used for processing
dbf = "C:\\TestFolder\\ProcessControlTable.dbf"
#Column within dbf table containing file paths 
myColumn = "FI_PATH"
#Temp list created to hold appended items from arcpy.Exists Function
Temp = []

#SearchCursorList created by using SearchCursorObject to create List 
FilePathList =[row[0] for row in arcpy.da.SearchCursor(dbf,myColumn)]
print(FilePathList)
for elements in FilePathList:
    if arcpy.Exists(elements):
        #If element in SearchCursorList Exists;
        #Define a variable called Exists and string object
        Exists = "1"
        Temp.append(Exists[0])
        print(Exists)

    else:
        DoesNotExist = "0"
        Temp.append(Exists[0])
        print(DoesNotExist)
        
print (Temp)

The output in the Python shell first prints the list containing file paths. Next, strings created from looping with the arcpy.Exists function are printed one by one in the correct order. Lastly, the Temp list is printed however all items in the list are the string object '1'. I want Temp list to contain strings created from the arcpy.Exists function looping in the correct order. The Temp list should print ['1','1','0','1','1','1','1','1','1','0']

Python Shell Output

I'm not sure what code will pull objects out of the loop and put it into a new list. I can't think of the logic with my limited Python and ArcPy knowledge.

Source Link
user128371
  • 129
  • 2
  • 7

Create a list and append objects created from function arcpy.Exists through a loop

I used a SearchCursor Object to create a List ,containing file paths, and saved the list to a variable called FilePathList.

Next, I iterate through elements within the list using a for loop. Within the for loop, I nested an if statement that contains the arcpy.Exist function. I am inserting elements from the FilePathList into the arcpy.exist function. When list elements are inserted into the function; if the element exists a data object string “1” is created. In addition, if the element does not exist a data object string "0" is created. I read that the arcpy.Exists() function returns a Boolean indicating whether the element exists.

I want to use the arcpy.Exists function to create string objects "1" representing exists and "0" representing does not exist. In the code below, I am able to print the string objects one by one,in the correct order, to the console. However, I would like to append the strings to an empty list in the order that they are printed. The order is important because I will eventually insert the created list into a new field within the dbf file. The field needs to be in the correct order because it corresponds and links to another field.

import arcpy

arcpy.env.workspace = r"C:\TestFolder"

#dbf table used for processing
dbf = "C:\\TestFolder\\ProcessControlTable.dbf"
#Column within dbf table containing file paths 
myColumn = "FI_PATH"
#Temp list created to hold appended items from arcpy.Exists Function
Temp = []

#SearchCursorList created by using SearchCursorObject to create List 
FilePathList =[row[0] for row in arcpy.da.SearchCursor(dbf,myColumn)]
print(FilePathList)
for elements in FilePathList:
    if arcpy.Exists(elements):
        #If element in SearchCursorList Exists;
        #Define a variable called Exists and string object
        Exists = "1"
        Temp.append(Exists[0])
        print(Exists)

    else:
        DoesNotExist = "0"
        Temp.append(Exists[0])
        print(DoesNotExist)
        
print (Temp)

The output in the python shell first prints the list containing file paths. Next, strings created from looping with the arcpy.Exists function are printed one by one in the correct order. Lastly, the Temp List is printed however all items in the list are the string object '1'. I want Temp List to contain strings created from the arcpy.Exist function looping in the correct order. The temp list should print ['1','1','0','1','1','1','1','1','1','0']

Python Shell Output

Im not sure what code will pull objects out of the loop and put it into a new list. I can't think of the logic with my limited python and arcpy knowledge.