Hello,
As I am doing layout design with arcpy.mp in AGP 3.0, I'm experiencing the misfortune of having to use the Python Window instead of a reliable IDE like PyCharm. The latest problem: when I need to create a new layout and pull data from another file geodatabase, setting the workspace seems to have no effect, and using arcpy.da.SearchCursor() consistently throws a RunTimeError: The workspace is not connected.
Code:
circ = 'AOI'
dlDate = '10102022'
arcpy.env.workspace = fr"D:\myPath\{circ}_{dlDate}.gdb"
cGDB = arcpy.env.workspace
arcpy.env.overwriteOutput = True
print(cGDB)
MBfcs = arcpy.ListFeatureClasses()
MBtbs = arcpy.ListTables()
MBSurtb = MBtbs[0]
surFields = [f.name for f in arcpy.ListFields(MBSurtb)]
print(surFields)
with arcpy.da.SearchCursor(MBSurtb, surFields) as tableParser:
for row in tableParser:
fctyID = row[1]
totSTR = row[3]
subStr = row[4]
subAdd = row[8]
nonStr = row[6]
wTxStr = row[10]
totSpn = row[11]
circMi = row[12]
condMi = row[14]
nCrcMi = row[15]
nonSpn = row[16]
datMin = row[17][4:]
datMax = row[18][4:]
fyrMin = row[17][:4]
fyrMax = row[18][:4]
Results:
D:\myPath\AOI_10102022.gdb
['OBJECTID', 'field1', 'field2', 'field3', 'field4', 'field5', 'field6', 'field7', 'field8', 'field9', 'field10', 'field11', 'field12', 'field13', 'field14', 'field15', 'field16', 'field17', 'field18']
Traceback (most recent call last):
File "<string>", line 26, in <module>
RuntimeError: The workspace is not connected.
I've tried compacting the geodatabase as a first step to remove any locks, removing my with statement for the search cursor, everything. It's seems like I can't redeclare variables? What could be happening here?
The behavior of the Python Window is truly baffling. The first time I ran this, it threw an error telling me that a float is not subscriptable; yet fields 17 and 18 are type Text. Then it defaulted to the disconnected workspace error described above, even after application restart.
try a notebook, you can vary environment settings
Notebooks in ArcGIS Pro—ArcGIS Pro | Documentation