Using a combination of 'In' and wildcards in IF statement?

943 views
Skip to first unread message

cb

unread,
Jan 27, 2010, 7:53:58 PM1/27/10
to Python - ARCGIS geoprocessing
I'm trying to get the following if statement to work:

prefix1 = 'beginning_of_a_bunch_of_feature_classes_'
prefix2 = 'beginning_of_a_bunch_of_other_feature_classes_'

if featClassName in (prefix1 + '*', prefix2 + '*',
'other_dataset'):
then do this chunk of code....

The statement evaluates properly for 'other_dataset', but I can't
figure out how to get a wildcard into there to properly evaluate the
other 2

Message has been deleted
Message has been deleted

tarkenton

unread,
Jan 28, 2010, 12:13:50 AM1/28/10
to Python - ARCGIS geoprocessing
Hey CB

I think the best way to accomplish this is to use a regular
expression. Regular expressions are a way of describing a text
pattern. They are super powerful, but with power comes PITA, in that
they take a while to figure out. A good starting place is the python
documentation:

http://docs.python.org/library/re.html

Another good place to get started with them is the python HOW-TO

http://www.python.org/doc/2.6/howto/regex.html

That said to get you started let me make sure I understand the
question.

You have some kind of prefix like:

prefix1 = 'startOfFile_'
prefix2 = 'anotherStartOfFile_'

and you want to be able to test a string to see if it starts with
either of these strings:

I think that is correct?

Instead of typing out in long detail the code into this window here, I
have put together a simple script that will hopefully explain how this
all works. The link is:


http://geopython.googlegroups.com/web/regularExpressionExample.py

Hope this helps, let me know if it doesn't or if I have answered the
wrong question!

Cheers

Kevin

cb

unread,
Jan 28, 2010, 11:24:26 AM1/28/10
to Python - ARCGIS geoprocessing
Thanks Kevin! I think it's going to work. Who knew wildcards were so
complicated in Python? Everything else is so straightforward!

> > other 2- Hide quoted text -
>
> - Show quoted text -

Reply all
Reply to author
Forward
Message has been deleted
Message has been deleted
0 new messages