while x <= leta:
Listfieldx = str("'" + str(tableList)+"'")
print Listfieldx
fieldList = arcpy.ListFields(Listfieldx,"*","*") while x <= leta:
Listfieldx = str("'" + str(tableList)+"'")
print Listfieldx
fieldList = arcpy.ListFields('River') #Export all the field properties of each table in the Geodatabse
import arcpy
from arcpy import env
# Overwrite pre-existing files
arcpy.env.overwriteOutput = True
# Set the current workspace
#
# Set local variables
#Create a new table
try:
geoDataBasePath = "P:/RAME/GIS/2011/Report.mdb"
env.workspace = geoDataBasePath
NewTable = "FieldProperties"
arcpy.CreateTable_management(geoDataBasePath, NewTable)
# For each field in the feature class, print all properties
# Set local variables
inFeatures = NewTable
fieldName1="name"
fieldName2="aliasName"
fieldName3="baseName"
fieldName4="domain"
fieldName5="isNullable"
fieldName6="precision"
fieldName7="required"
fieldName8="scale"
fieldName9="type"
fieldName10="length"
fieldName11="editable"
fieldName12="FC"
fieldLength=255
# Execute AddField new fields
arcpy.AddField_management(inFeatures, fieldName1, "TEXT", "", "", fieldLength)
arcpy.AddField_management(inFeatures, fieldName2, "TEXT", "", "", fieldLength)
arcpy.AddField_management(inFeatures, fieldName3, "TEXT", "", "", fieldLength)
arcpy.AddField_management(inFeatures, fieldName4, "TEXT", "", "", fieldLength)
arcpy.AddField_management(inFeatures, fieldName5, "TEXT", "", "", fieldLength)
arcpy.AddField_management(inFeatures, fieldName6, "TEXT", "", "", fieldLength)
arcpy.AddField_management(inFeatures, fieldName7, "TEXT", "", "", fieldLength)
arcpy.AddField_management(inFeatures, fieldName8, "TEXT", "", "", fieldLength)
arcpy.AddField_management(inFeatures, fieldName9, "TEXT", "", "", fieldLength)
arcpy.AddField_management(inFeatures, fieldName10, "TEXT", "", "", fieldLength)
arcpy.AddField_management(inFeatures, fieldName11, "TEXT", "", "", fieldLength)
arcpy.AddField_management(inFeatures, fieldName12, "TEXT", "", "", fieldLength)
#List all tables in the Geodatabase
tableList = arcpy.ListTables()
for table in tableList:
print table
#how many tables are there
leta = len(tableList)
print leta
x=0
#loop through all tables
while x <= leta:
Listfieldx = str("'" + str(tableList)+"'")
print Listfieldx
fieldList = arcpy.ListFields(Listfieldx,"*","*")
print str(fieldList)
for field in fieldList:
print 1
NewList=[]
fc=str(tableList)
print fc
NewList.extend ([str(fc),str(field.name),str(field.aliasName),str(field.baseName),str(field.domain),str(field.isNullable),str(field.precision),str(field.required),str(field.scale), str(field.type),str(field.length),str(field.editable)])
print NewList
cursor = arcpy.InsertCursor(fc)
print 2
row = cursor.newRow()
row.FC=NewList[11]
row.name = NewList[0]
row.aliasName = NewList[1]
row.baseName = NewList[2]
row.domain = NewList[3]
row.isNullable = NewList[4]
row.precision = NewList[5]
row.required = NewList[6]
row.scale = NewList[7]
row.type = NewList[8]
row.length = NewList[9]
row.editable = NewList[10]
print 3
cursor.insertRow(row)
del NewList
x=x+1
del row
print 99
del cursor
del NewList
except:
print "\nError!\n"
del row
del cursor
del NewList
tableList = arcpy.ListTables() for table in tableList: fieldList = arcpy.ListFields(table) for field in fieldList:
tableList = arcpy.ListTables() for table in tableList: print table # how many tables are there leta = len(tableList) print leta x=0 # loop through all tables while x < leta: Listfieldx = tableListfieldList = arcpy.ListFields(Listfieldx,"*","*") for field in fieldList: print field.name x += 1
import arcpy
from arcpy import env
# Set the current workspace
#
env.workspace = "C:/Data/Municipal.gdb"
# For each field in the Hospitals feature class, print
# the field name, type, and length.
fieldList = arcpy.ListFields("Hospitals")
for field in fieldList:
print "%s is a type of %s with a length of %i" % (field.name, field.type, field.length)
# Export all the field properties of each table in the Geodatabse to a new table # in the same Geodatabase. If the table already exists the old one will be # overwritten. If a problem occurs a message will appear in the python window, so # check the window before closing. import arcpy from arcpy import env # Overwrite pre-existing files arcpy.env.overwriteOutput = True # Get input information. Target Geodatabase and Name of the New table containing # the Table field properties. geoDataBasePath=arcpy.GetParameterAsText(0) NewTable=arcpy.GetParameterAsText(1) # Set the current workspace # Create a new table try: env.workspace = geoDataBasePath arcpy.CreateTable_management(geoDataBasePath, NewTable) # Naming the fields of the outputtable inFeatures = NewTable fieldName1="field_name" fieldName2="aliasName_" fieldName3="baseName_" fieldName4="domain_" fieldName5="isNullabl_" fieldName6="precision_" fieldName7="required_" fieldName8="scale_" fieldName9="type_" fieldName10="length_" fieldName11="editable_" fieldName12="Table_Name" fieldLength=255 # Execute AddField new fields. All fields are set as text even if they contain numbers. arcpy.AddField_management(inFeatures, fieldName12, "TEXT", "", "", fieldLength) arcpy.AddField_management(inFeatures, fieldName1, "TEXT", "", "", fieldLength) arcpy.AddField_management(inFeatures, fieldName2, "TEXT", "", "", fieldLength) arcpy.AddField_management(inFeatures, fieldName3, "TEXT", "", "", fieldLength) arcpy.AddField_management(inFeatures, fieldName4, "TEXT", "", "", fieldLength) arcpy.AddField_management(inFeatures, fieldName5, "TEXT", "", "", fieldLength) arcpy.AddField_management(inFeatures, fieldName6, "TEXT", "", "", fieldLength) arcpy.AddField_management(inFeatures, fieldName7, "TEXT", "", "", fieldLength) arcpy.AddField_management(inFeatures, fieldName8, "TEXT", "", "", fieldLength) arcpy.AddField_management(inFeatures, fieldName9, "TEXT", "", "", fieldLength) arcpy.AddField_management(inFeatures, fieldName10, "TEXT", "", "", fieldLength) arcpy.AddField_management(inFeatures, fieldName11, "TEXT", "", "", fieldLength) #List all tables in the Geodatabase tableList = arcpy.ListTables() x=0 # For all tables list all fields for table in tableList: try: fieldList = arcpy.ListFields(table) for field in fieldList: #Get the name of the current table nametable=str(tableList) #make a new list and add the name of the table and the properties #of each field to the list NewList=[] NewList.extend ([str(field.name),str(field.aliasName),str(field.baseName),str(field.domain),str(field.isNullable),str(field.precision),str(field.required),str(field.scale), str(field.type),str(field.length),str(field.editable), nametable]) #Use an insert cursor to add new rows with the field properties cursor = arcpy.InsertCursor(NewTable) row = cursor.newRow() row.field_name = NewList[0] row.aliasName_ = NewList[1] row.baseName_ = NewList[2] row.domain_ = NewList[3] row.isNullabl_=NewList[4] row.precision_ = NewList[5] row.required_ = NewList[6] row.scale_ = NewList[7] row.type_ = NewList[8] row.length_ = NewList[9] row.editable_ = NewList[10] row.Table_Name = NewList[11] cursor.insertRow(row) x=x+1 #add warning message in the python window if a problem with the table appears. #Even a problem is reported the output is normally fine. But check to make sure. except: print "The crazy clown says there is a problem with table ", nametable, ". Check the results for this table." except: print "\nError!\n" del row del cursor del NewList
From the ESRI arcpy.listfields online help:import arcpy from arcpy import env # Set the current workspace # env.workspace = "C:/Data/Municipal.gdb" # For each field in the Hospitals feature class, print # the field name, type, and length. fieldList = arcpy.ListFields("Hospitals") for field in fieldList: print "%s is a type of %s with a length of %i" % (field.name, field.type, field.length)
I don't know what you are trying to accomplish with the Asterisks ** inside your fieldlist, but if you delete them I figure it should work.
a = arcpy.ListFields("Hospitals")feature = 'Hospitals'
a = arcpy.ListFields(feature) #no quote marks - feature is a variablefeature = arcpy.GetParamaterAsText(0)
a = arcpy.ListFields(feature) #no quote marks - feature is, once again, a variablefieldName1="field_name" fieldName2="aliasName_" fieldName3="baseName_" fieldName4="domain_" fieldName5="isNullabl_" fieldName6="precision_" fieldName7="required_" fieldName8="scale_" fieldName9="type_" fieldName10="length_" fieldName11="editable_" fieldName12="Table_Name" fieldLength=255 # Execute AddField new fields. All fields are set as text even if they contain numbers. arcpy.AddField_management(inFeatures, fieldName12, "TEXT", "", "", fieldLength) arcpy.AddField_management(inFeatures, fieldName1, "TEXT", "", "", fieldLength) arcpy.AddField_management(inFeatures, fieldName2, "TEXT", "", "", fieldLength) arcpy.AddField_management(inFeatures, fieldName3, "TEXT", "", "", fieldLength) arcpy.AddField_management(inFeatures, fieldName4, "TEXT", "", "", fieldLength) arcpy.AddField_management(inFeatures, fieldName5, "TEXT", "", "", fieldLength) arcpy.AddField_management(inFeatures, fieldName6, "TEXT", "", "", fieldLength) arcpy.AddField_management(inFeatures, fieldName7, "TEXT", "", "", fieldLength) arcpy.AddField_management(inFeatures, fieldName8, "TEXT", "", "", fieldLength) arcpy.AddField_management(inFeatures, fieldName9, "TEXT", "", "", fieldLength) arcpy.AddField_management(inFeatures, fieldName10, "TEXT", "", "", fieldLength) arcpy.AddField_management(inFeatures, fieldName11, "TEXT", "", "", fieldLength)
fieldLength=255 field_names = ["field_name", "aliasName_", "baseName_", "domain_", "isNullabl_", "precision_", "required_", "scale_", "type_", "length_", "editable_"] for field_name in field_names: arcpy.AddField_management(inFeatures, field_name, 'TEXT', '', '', field_length)