AnsweredAssumed Answered

Creating a list of tuples from arcpy.ListFields()

Question asked by jborgion Champion on Jun 2, 2020
Latest reply on Jun 2, 2020 by jborgion

I'd like to create a list of tuples where each tuple contains the data from the fields of one feature class: the objective is to iterate through the list and add fields of the name, type and length provided in each of the tuples to a different feature class.  I've hit a snag and I'm sure how to un-snag myself:

fc = r'C:\path\to_gdb\featureClass'
fieldList = []
for f in arcpy.ListFields(fc):
    x = (f'("{}","{f.type}",{f.length})')

works pretty good, but not quite perfect.  Each of the tuples is bounded by single quotes so if I try to use the tuple indexes to extract a tuple element, things head south:



I can cheat (and I have) and just copied and pasted fieldList to notepad and deleted the single quotes, but that's using a hammer; how would I create a clean list of tuples without the bounding single quotes:

[('OBJECTID', 'OID', 4),
('SHAPE', 'Geometry', 0),
('siteaddid', 'String', 20),
('addressptid', 'String', 20),
('rclnguid', 'String', 254),
('discrpagid', 'String', 75),
('preaddrnum', 'String', 5),
('addrnumsuf', 'String', 5),