I'm wondering how to have a single parameter in the arcpy.FeatureClassToFeatureClass_conversion()
function instead of repeating the block of code for two variables (Address_Points and Street), basically.
From what I understand, the way this script is set up now, the outer loop prints once for each variable. Then it prints once for each variable again in the inner loop. It runs as I expect, namely with no errors and saves the two feature classes as shapefiles in the Test folder.
import arcpy
arcpy.env.overwriteOutput = True
# variables
infeatures = [r'fullpath\gisedit.DBO.Street',
r'fullpath\gisedit.DBO.Address_Points']
outpath = r'fullpath\GISstaff\Jared\Test'
outfeatures = ['WillCounty_Streets', 'WillCounty_AddressPoints']
# loop and print feature classes
for infs in infeatures:
print infs
for otfs in outfeatures:
print otfs
arcpy.FeatureClassToFeatureClass_conversion(infs,outpath,otfs)
Result:
>>> fullpath\gisedit.DBO.Street
WillCounty_Streets
WillCounty_AddressPoints
fullpath\gisedit.DBO.Address_Points
WillCounty_Streets
WillCounty_AddressPoints
How do I get the print out to look like this?
WillCounty_Streets
WillCounty_AddressPoints
I tried the nested loop approach to copy features classes and it bombs out because of that 'second pass'.
Try this instead....
for i in range(len(infeatures)):
arcpy.FeatureClassToFeatureClass_conversion(infeatures[i],outputws,outfeatures[i])
This just steps through your infeatures[] by index and uses the same index number of the outfeatures[] list to create the out feature. In this approach, you need the same number of infeatures[] as outfeatures[]....
infeatures = [r'fullpath\gisedit.DBO.Street',
r'fullpath\gisedit.DBO.Address_Points']
outpath = r'fullpath\GISstaff\Jared\Test'
outfeatures = ['WillCounty_Streets', 'WillCounty_AddressPoints']
in_out = list(zip(infeatures, outfeatures))
for i,j in in_out:
print("in: {} out: {}".format(i, j))
in: fullpath\gisedit.DBO.Street out: WillCounty_Streets
in: fullpath\gisedit.DBO.Address_Points out: WillCounty_AddressPoints
for i, j in in_out:
arcpy.FeatureClassToFeatureClass(i, outpath, j) # or something like that
Thanks Dan! I've never used zip() before....
Joe... I should have mentioned that the 'list' part of list(zip... is required for python 3... it may not be needed for python 2
Thanks for the help. I'll have to come back to this because i've been put on another project that should come first.