use more than one search term in ListTables

161
1
Jump to solution
07-30-2021 02:21 PM
Trippetoe
Occasional Contributor III

Hello.

Is there a way to pass multiple search terms (or wildcards as described in the documentation) to the arcpy function ListTables?  I've tried passing in a comma separate list of strings and passing in an array of strings. Neither of those approaches worked. 

I need to work with all the tables that start with 'Ad' and those that start with 'T'. What i am doing now is calling the ListTables function twice (see below). This gets the results I need, but it seems very heavy - i have to go to the workspace twice to get the list i'm after:

datalist = arcpy.ListTables("PES.IPM.Ad*") + arcpy.ListTables("PES.IPM.T*")
 
I'd rather make the call once, passing something like this instead:
 
datalist = arcpy.ListTables(["PES.IPM.Ad*", "PES.IPM.T**" ])
 
Is such a thing possible?
Thank you.
0 Kudos
1 Solution

Accepted Solutions
DanPatterson
MVP Esteemed Contributor

No.

ListTables—ArcGIS Pro | Documentation

concatenating the lists is fine even if one of the lists is empty

q = ['a', 'b']
q0 = []
q + q0
['a', 'b']

you can use a list comprehension to make it look a tad better

table_lst = [arcpy.ListTables(i) for i in ["PES.IPM.Ad*", "PES.IPM.T*"]]

... sort of retired...

View solution in original post

1 Reply
DanPatterson
MVP Esteemed Contributor

No.

ListTables—ArcGIS Pro | Documentation

concatenating the lists is fine even if one of the lists is empty

q = ['a', 'b']
q0 = []
q + q0
['a', 'b']

you can use a list comprehension to make it look a tad better

table_lst = [arcpy.ListTables(i) for i in ["PES.IPM.Ad*", "PES.IPM.T*"]]

... sort of retired...

View solution in original post