I want to create 12 feature classes from a tuple, and I would like to have specific names that start form well_0 and end with well_11.

in_FC = "E:/gis payannameh/TABU search/data/90spring_new.shp"
out_FC = r'E:\gis payannameh\Pychram_tabu\output.gdb'
well = ('10,24,38,41', '17,26,34,47', '5,7,18,25', '7,12,26,46', '2,12,23,36', '7,18,21,43', '2,13,16,39', '5,8,32,43', '1,9,17,44', '8,13,30,46', '2,14,34,37','3,15,12,9')
for i in range(len(well)):
     templayer = "templayer_{}".format(i)
     sql = """ {0} IN ({1})""".format("FID",well[i])

but when I use ListFeatureClasses for i=2 it shows well_10, [well_0,well_1,well_10,well_11,well_2,...well_9].I would Like to create each feature class'name with its index name(i) regularly something like [well_0,well_1,well_2,...,well_11].

  • 1
    Use 01, 02 etc instead.
    – FelixIP
    Sep 30, 2021 at 17:47

2 Answers 2


You can use enumerate and Select_analysis:

import arcpy, os

in_FC = "E:/gis payannameh/TABU search/data/90spring_new.shp"
out_FC = r'E:\gis payannameh\Pychram_tabu\output.gdb'
well = ('10,24,38,41', '17,26,34,47', '5,7,18,25', '7,12,26,46', '2,12,23,36', '7,18,21,43', '2,13,16,39', '5,8,32,43', '1,9,17,44', '8,13,30,46', '2,14,34,37','3,15,12,9')

for e, w in enumerate(well):
     sql = """{0} IN{1}""".format(arcpy.AddFieldDelimiters(datasource=in_FC, field=arcpy.Describe(in_FC).OIDFieldName), tuple([int(v) for v in w.split(','))]) #Split the string into a list, convert to tuple
     newname = 'well_{0}'.format(e)
     arcpy.Select_analysis(in_features=in_FC, out_feature_class=os.path.join(out_FC, newname), where_clause=sql)
  • @BERA.Its Create [u'well_0.shp', u'well_1.shp', u'well_10.shp', u'well_11.shp', u'well_2.shp', u'well_3.shp', u'well_4.shp', u'well_5.shp', u'well_6.shp', u'well_7.shp', u'well_8.shp', u'well_9.shp'].and didn't change Sep 30, 2021 at 10:59
  • I dont understand what you are saying
    – BERA
    Sep 30, 2021 at 11:28
  • @BERA.I would like to when I use arcpy.ListFeatureClasses() in out_FC for e=2 show me well_2.shp not well_10.shpI hope you understand. Sep 30, 2021 at 14:50
  • Not really. You have duplicate FIDs in your well list, you know that right?
    – BERA
    Sep 30, 2021 at 14:55
  • I checked I don't have duplicate FIDs in well. Sep 30, 2021 at 15:08

I hope I understand your confusion. Unexpected result caused by the way text variables are sorted. This code:

List1,List2 =[],[]
for i in range (11):
    List1.append('W_%i' %i)
    List2.append('W_%s' %str(i).zfill(2))
for item in zip(List1,List2):
    print '%s%s%s' %(item[0].rjust(5),chr(9),item[1])


  W_0   W_00
  W_1   W_01
 W_10   W_02
  W_2   W_03
  W_3   W_04
  W_4   W_05
  W_5   W_06
  W_6   W_07
  W_7   W_08
  W_8   W_09
  W_9   W_10

You need to add leading zero in string format, so, simply change last bit of your code from:



(templayer,out_FC,"well_%s" %str(i).zfill(2)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.