I guess this shows my ignorance of the internet today, but if we have code/ideas how would it be best to communicate that with you fellows? I'm sure there's some fancy github way of doing all that... Sadly I'm pretty ignorant of that and stuck in the internet of like 2003 for some reason. Looks like these functions (and frankly, much better/fancier ones!) are already in your arcapi library, but for what it's worth comparing independent invention and all that, here's a few of mine I use all the time... I'd love to contribute some time to ideas/code sometime. Send me an email: chris.snyder( at ) dnr.wa.govdef listFields(inputTable, wildCard = "", fieldType = ""):
"""Lists fields (and selected properties) for inputTable"""
fieldList = arcpy.ListFields(inputTable, wildCard, fieldType)
#FORMATTING INFO: NAME = 50 spaces, TYPE = 15 spaces, LENGTH = 15 spaces, SCALE = 15 spaces, PRECISION = 15 spaces
print "NAME " + "TYPE " + "LENGTH " + "SCALE " + "PRECISION "
print "-" * 100
for field in fieldList:
print str(field.name)[0:50] + " "*(50-len(field.name)) \
+ str(field.type)[0:15] + " "*(15-len(str(field.type))) \
+ str(field.length)[0:15] + " "*(15-len(str(field.length))) \
+ str(field.scale)[0:15] + " "*(15-len(str(field.scale))) \
+ str(field.precision)[0:15] + " "*(15-len(str(field.precision)))
def listRecs(inputTable, numberOfRecordsToList = 25, whereClause = ""):
"""Lists field names and corresponding field values in inputTable"""
fieldNamesList = [f.name for f in arcpy.ListFields(inputTable)]
rowCount = 1
recordCount = int(arcpy.GetCount_management(inputTable).getOutput(0))
if int(numberOfRecordsToList) > recordCount:
numberOfRecordsToList = recordCount
searchRows = arcpy.da.SearchCursor(inputTable, ["*"], whereClause)
searchRow = searchRows.next()
while rowCount <= int(numberOfRecordsToList):
print "RECORD #" + str(rowCount)
print "-" * 50
for fieldName in fieldNamesList:
try:
print fieldName + ": " + str(searchRow[fieldNamesList.index(fieldName)])
except:
print fieldName + ": !?!"
print ""
print ""
rowCount = rowCount + 1
searchRow = searchRows.next()
del searchRow, searchRows
print ""
print ""
print "LISTED " + str(numberOfRecordsToList) + " RECORDS"