spooky arcpy wildcards

3955
3
03-07-2016 05:52 AM
LotharUlferts
New Contributor III

>>> arcpy.ListToolboxes()

[u'3D Analyst Tools(3d)',

u'Analysis Tools(analysis)',

......

u'Toolbox(interactiveTools)']

>>> [i for i in arcpy.ListToolboxes() if i.endswith('analysis)')]

[u'Analysis Tools(analysis)']

So far, everythings looking good.

You may think: Ok,  it's little bit complicated. Why don't you use wildcards?

>>> arcpy.ListToolboxes( '*analysis)' )

[]

No string ends with "analysis)"??. Did I missed something?

>>> arcpy.ListToolboxes( '*)' )

[]

UUPS!! No string ends with ")".  Should I call my ocoulist  ??

>>> ap.ListToolboxes('*analysis')

[u'Analysis Tools(analysis)']

HEURECA!!

Parenthesis are for ArcGIS "signs non gratia": Good enough for printing but not grand enough to receive attention by nobly arcpy-wildcards. But, thanks God!, my beloved core Python is a democratic Python and it's more logical.

0 Kudos
3 Replies
WesMiller
Regular Contributor III

This works without the ')'

>>> import arcpy
>>> toolList = arcpy.ListToolboxes('*analysis')
>>> toolList
[u'Analysis Tools(analysis)']
0 Kudos
LotharUlferts
New Contributor III

The searchstring doesnt end with parenthesis, the result founded do. IMO it's unlogical.

0 Kudos
LotharUlferts
New Contributor III

One supplement to my first comment: The algorythm behind wildcard seems to be an legacy from 9.3.

Like in these old times upper- and lowercase are unpythonical ignored: You are free to write '*ANalySis' or '*analysis' or whatever simular you want to write , if you are looking for '(analysis)' in fact. 

0 Kudos