# Select all records that are in capital letters

2030
9
12-11-2017 12:54 PM
Occasional Contributor

I am trying to pull items out of an attribute table. I want to pull out all county names that are in capital letters. I was using UPPER (County) = 'ANDREWS' but it was only pulling up Andrews. I need to pull up several different named counties.

Tags (1)
1 Solution

Accepted Solutions
MVP Emeritus

No on to what you have to do... since I don't think you can do the query all at once.

Add a field to contain a string or boolean

Calculate the new field using

allcaps(!YourFieldNameHere')

and calculate into a boolean or string field.  then you have a field for querying.

``````def allcaps(a):
"""check for all caps"""
uc = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
n = len(a)
m = sum([i in uc for i in a])
return n == m

# ---- test case

a = 'ANDREWS'
allcaps(a)
True

b = 'AnDrews'
allcaps(b)
False‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍``````
9 Replies
MVP Emeritus

python lesson

I think the field calculator/query stuff supports the 'IN' operator.. what you want is to compare to the first value of the string to the capital letters in a list

A demo, but this can easily be made into a function if you don't want to copy ucl over obviously so your expression would be

'Yourfield'[0] in uc  # or whatever surrounding characters are used for field names

``````uc = string.ascii_uppercase

# ---- make a list for future reference
ucl = list(uc)
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

#  ucl  = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',
'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']

# --- a test
a = 'ANDREWS'  # now 'a' would be your field
a[0] in ucl
True

a[1] in ucl
True

# ---- a quick test for lowercase

'b' in ucl
False‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍``````
Occasional Contributor

So there is not a simple syntax for inside the select by attributes??

MVP Emeritus

No on to what you have to do... since I don't think you can do the query all at once.

Add a field to contain a string or boolean

Calculate the new field using

allcaps(!YourFieldNameHere')

and calculate into a boolean or string field.  then you have a field for querying.

``````def allcaps(a):
"""check for all caps"""
uc = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
n = len(a)
m = sum([i in uc for i in a])
return n == m

# ---- test case

a = 'ANDREWS'
allcaps(a)
True

b = 'AnDrews'
allcaps(b)
False‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍``````
Occasional Contributor

Bummer!! Thanks for the help.

MVP Emeritus

What if you calculated the names to be ALL UPPER CASE or All Proper Case?  (Hmmmm.... sounds dangerously like a standard....)

Using the Python parser in the Field calculator:

(Pre-Logic Script Code box)

``````def myUpper(instring):
x = instring.upper()
return x‍‍‍``````
``myUpper(!YourFieldName!)‍‍``

changed slightly:

``````def myProper(instring):
x = instring.title()
return x‍‍‍‍‍‍``````
`` myProper(!YourFieldName!)‍‍``

I started with the field value of  jose diablo and get JOSE DIABLO and Jose Diablo respectively....

That should just about do it....
MVP Emeritus

as long as you leave the original field alone... and calculate in a new field... then you would have a choice... but what if they were to be all lower... or upper then lower... the possibilities are endless... there are so many 'standards' to choose from as one of our illustrious compatriots said

MVP Emeritus

I'm an upper case kind of guy.  The data bases I manage are UC.  Nothing else....

That should just about do it....
MVP Emeritus

I am too much pythonic... all lower case for me

MVP Emeritus

That should just about do it....