Solved! Go to Solution.
"FIPS_PARIS = '" + fip + "'"
Still having problems with the where clause. The select features will not go through the list loop. It only wants to find the list name since it is in quotes.
I just can't figure this out.
arcpy.TableSelect_analysis(inputTable, outputWorkspace +\ "\\fips_" + str(fip) + ".dbf", \ "FIPS_PARIS = " + "\'" + fip + "\'")
query = "FIPS_PARIS = \'%s\'" % fip outTable = os.path.join(outputWorkspace,"fips_%s.dbf" % fip) arcpy.TableSelect_analysis(inputTable,outTable,query)
query = "FIPS_PARIS = \'{0}\'".format(fip) outTable = os.path.join(outputWorkspace,"fips_{0}.dbf".format(fip) arcpy.TableSelect_analysis(inputTable,outTable, query)
import arcpy FIPS = "C:\\Users\\D2148\\Documents\\Maps\\FIPS" c = 0 # FIPSlist = ('001', '003', '005', '007', '009', '011', '013', #Try smaller list first #'015', '017', '019', '021', '023', '025', '027', #'029', '031', '033', '035', '037', '039', '041', #'043', '045', '047', '049', '051', '053', '055', #'057', '059', '061', '063', '065', '067', '069', #'071', '073', '075', '077', '079', '081', '083', #'085', '087', '089', '091', '093', '095', '097', #'099', '101', '103', '105', '107', '109', '111', #'113', '115', '117', '119', '121', '123', '125', #'127') #FIPSnum = (001, 003, 005, 007, 009, 011, 013, #Try Smaller list first # 015, 017, 019, 021, 023, 025, 027, # 029, 031, 033, 035, 037, 039, 041, # 043, 045, 047, 049, 051, 053, 055, # 057, 059, 061, 063, 065, 067, 069, # 071, 073, 075, 077, 079, 081, 083, # 085, 087, 089, 091, 093, 095, 097, # 099, 101, 103, 105, 107, 109, 111, # 113, 115, 117, 119, 121, 123, 125, # 127) FIPSlist = ('001', '003', '005') FIPSnum = (001, 003, 005) while c < len(FIPSlist): for fip in FIPSlist: query = "FIPS_PARIS ='" + fip + "'" # arcpy.TableToTable_conversion("TRIAL1",FIPS,"FIPS" + FIPSlist+ ".dbf",query) arcpy.TableSelect_analysis("Master_TAHI", FIPS + "\\FIPS" + FIPSlist + ".dbf",query) c = c + 1
However, it will not loop anymore
FIPSlist = ('001', '003', '005') for fip in FIPSlist: query = "FIPS_PARIS ='" + fip + "'" arcpy.TableSelect_analysis("Master_TAHI", FIPS + r"\FIPS" + fip + ".dbf",query)
import arcpy FIPS = "C:\\Users\\D2148\\Documents\\Maps\\FIPS" FIPSlist = ('001', '003', '005', '007', '009', '011', '013', '015', '017', '019', '021', '023', '025', '027', '029', '031', '033', '035', '037', '039', '041', '043', '045', '047', '049', '051', '053', '055', '057', '059', '061', '063', '065', '067', '069', '071', '073', '075', '077', '079', '081', '083', '085', '087', '089', '091', '093', '095', '097', '099', '101', '103', '105', '107', '109', '111', '113', '115', '117', '119', '121', '123', '125', '127') for fip in FIPSlist: query = "FIPS_PARIS ='" + fip + "'" arcpy.TableSelect_analysis("Master_TAHI", FIPS + "\\FIPS" + fip + ".dbf",query)
I'm new to Python and what I want to do is very similar, only my list is of integer values (created by using range()). Using the above example, how would the query expression be changed if FIPSlist was integer instead of string (query field is also integer)?
FIPSlist = range(5) # (0,1,2,3,4) for fip in FIPSlist: query = "FIPS_PARIS = " + str(fip) arcpy.TableSelect_analysis("Master_TAHI", FIPSpath + r"\FIPS" + str(fip) + ".dbf",query)
import arcpy myOutputTable = r"C:\temp\test.gdb\input" for i in range(1,1001): myOutputTable = r"C:\temp\test.gdb\table_id_" + str(i) arcpy.TableSelect_analysis(myInputTable, myOutputTable, "MY_ID = " + str(i))