Stuck ok step 2, how can I fix this?
import arcpy
import pandas as pd
from datetime import datetime, timezone
import pandas
import urllib
import http
import sys
# Import the geodatabase table
ItemsURL = "O:\\CheckURLs\\MyProject.gdb\\HubitemCatalogList"
# Select the fields to print
fields = ['Item_URL']
with arcpy.da.SearchCursor(ItemsURL, fields) as cursor:
for i in range(5):
for row in cursor:
print(row)
break
print('Geodatabase table was read in just fine :)')
# Create a list of URLs from Item_URL field
URL_List = []
URL_List = ItemsURL['Item_URL']
Print('List created successfully')
Error:
URL_List = ItemsURL['Item_URL']
TypeError: string indices must be integers
Solved! Go to Solution.
Right now, you're asking it to return an index from the string
O:\\CheckURLs\\MyProject.gdb\\HubitemCatalogList"
So like, ItemsURL[0] would return"O". This is not what you're trying to do.
Try this instead?
Basically, bring the URL_List up and then append each value into it as you iterate over the rows.
import arcpy
import pandas as pd
from datetime import datetime, timezone
import pandas
import urllib
import http
import sys
# Import the geodatabase table
ItemsURL = "O:\\CheckURLs\\MyProject.gdb\\HubitemCatalogList"
# Select the fields to print
fields = ['Item_URL']
URL_List = []
with arcpy.da.SearchCursor(ItemsURL, fields) as cursor:
for i in range(5):
for row in cursor:
print(row)
# Add the Item_URL value to the list.
URL_List.append(row[0])
break
print('Geodatabase table was read in just fine :)')
print('List created successfully')
print(URL_List)
Right now, you're asking it to return an index from the string
O:\\CheckURLs\\MyProject.gdb\\HubitemCatalogList"
So like, ItemsURL[0] would return"O". This is not what you're trying to do.
Try this instead?
Basically, bring the URL_List up and then append each value into it as you iterate over the rows.
import arcpy
import pandas as pd
from datetime import datetime, timezone
import pandas
import urllib
import http
import sys
# Import the geodatabase table
ItemsURL = "O:\\CheckURLs\\MyProject.gdb\\HubitemCatalogList"
# Select the fields to print
fields = ['Item_URL']
URL_List = []
with arcpy.da.SearchCursor(ItemsURL, fields) as cursor:
for i in range(5):
for row in cursor:
print(row)
# Add the Item_URL value to the list.
URL_List.append(row[0])
break
print('Geodatabase table was read in just fine :)')
print('List created successfully')
print(URL_List)