Hot answers tagged

9

Please consider using an arcpy.da.SearchCursor: FieldNameDict = {} with arcpy.da.SearchCursor(dbf,[myfield,'AP_ZIP','AP_STATE','AP_CITY','AP_FULLADD','AP_BUILDIN']) as rows: for row in rows: FieldNameDict[row[0]] = row[1:] # everything but the first element As the row is a tuple that is returned you can use simple indexing [1:] to ...


6

I have not tested this but it is a one liner that uses dictionary comprehension, an arcpy.da.SearchCursor() and the indexing syntax from the answer by @MichaelStimson: FieldNameDict = {row[0]:[row[1:]] for row in arcpy.da.SearchCursor(dbf,[myfield,'AP_ZIP','AP_STATE','AP_CITY','AP_FULLADD','AP_BUILDIN'])}


4

Easier than casting your data into dictionaries would be to use the native list fields function in arcpy to get list of your field names. Then put those lists into sets and do the difference and intersection of those lists. import arcpy inFC1 = r"C:\gTemp\deleteme.shp" inFC2 = r"C:\gTemp\kblirestricedareas.shp" #Get the field names as lists... fields1 = [...


2

ArcGIS Pro's Layout class has very few Properties. If you were able "to add multiple snapping guides to a layout in ArcGIS Pro" using ArcPy then I suspect that there would need to be a property that is a list of Guide objects. ArcPy for ArcGIS Pro does not have a Guide class to create those Guide objects. If this is important to you then you could post an ...


1

This should work, fields = ['R_ID', 'Type'] with arcpy.da.UpdateCursor(sorFeat, fields) as cursor: # Update R_ID field based on Type field. # Type is either WHITE, BLACK. for row in cursor: # Update Id field if Type is BLACK. if row[1] == 'BLACK': row[0] = autoIncrement() cursor.updateRow(row) You could ...


1

Iterate through your first dictionary and pull out the key and the list of fields. Pull out your second list of fields using the same key. create an uppercase list of your second fields. Iterate through your first list of fields. After capitalization check if it's in the uppercase second list. You can create two lists this way; one of found one of not found. ...


1

As the error message indicates, the return value of GetCount_management is a Result object. The documentation for GetCount includes an example of how to extract the return value, by casting the Result.GetOutput() value to integer. Rewriting your code to use Style Guide for Python (PEP 8) recommended leading lowercase variable names, the result is: ...


1

I finally found a solution : the second attempt was a good attempt, but as @KHibma mentionned, I crossed arcpy and arcgis-python-api. I tried to connect to AGOL with argis.gis.GIS while I should connect with arcpy. As the error message were not saying anything about this, it was quite difficult to understand ! Here is my code if it can help ! To summarize :...


Only top voted, non community-wiki answers of a minimum length are eligible