Fix your PYTHONPATH
. From ArcGIS help:
When using an import statement, Python looks for a module matching that name in the following locations (and in the following order):
- Paths specified in the
PYTHONPATH
system environment variable
- A set of standard Python folders (the current folder,
C:\python2x\lib
, C:\python2x\Lib\site-packages
, and so on)
- Paths specified inside any
.pth
file found in 1 and 2
For more information on this, see the following: http://docs.python.org/install/index.html#modifying-python-s-search-path.
The installation of ArcGIS 10.0 products will install Python 2.6 if it isn't already installed. The installation will also add the file Desktop10.pth
(or Engine10.pth
or Server10.pth
) into python26\Lib\site-packages
. The contents of this file are two lines containing the path to your system's ArcGIS installation's arcpy and bin folders. These two paths are required to import ArcPy successfully in Python version 2.6.
When using an import statement, Python refers to your system's PYTHONPATH
environment variable to locate module files. This variable is set to a list of directories.
Tip:
If importing ArcPy produces either of the following errors, the required modules could not be found:
ImportError: No module named arcpy
ImportError: No module named arcgisscripting
To address this, browse using Windows Explorer to the python26\Lib\site-packages
folder and add or edit the Desktop10.pth
file. The file should contain the two lines shown below (corrected to your system's path if they do not match):
C:\Program Files\ArcGIS\Desktop10.0\arcpy
C:\Program Files\ArcGIS\Desktop10.0\bin
You combine whereClause3 and whereClause4 with the AND operator.
As gm70560 wrote, the variables workforceField, workforceindex are not defined. That's why, first you have to define them. I guess workforceindex is a double or at least a number datatype like farmfieldindex. So you have to Change:
whereClause3 = "\"%s\" = '%s'" % (workforceField, workforceindex)
to:
whereClause3 = "\"%s\" = %s" % (workforceField, workforceindex)
The whereClause4 is not defined (commented out). You have to change
whereClause = "\"%s\" = '%s'" % (farmField, farmfieldindex)
to:
whereClause4 = "\"%s\" = %s" % (farmField, farmfieldindex)
Is that right? (I removed the single quotes for the farmfieldindex)
Another reason for getting an error should be the following:
whereClause3 + "AND" + whereClause4
Is the same like: "\"%s\" = %s" + "AND" + "\"%s\" = %s"
Is the same like: "\"%s\" = %sAND\"%s\" = %s"
Thus, you have no blank between the value (workforceindex) of the first part of the where clause and the AND Operator. Change the Select Layer by Attribute Function to the following and it should work:
arcpy.SelectLayerByAttribute_management(countiesL, "NEW_SELECTION", whereClause3 + " AND " + whereClause4)
If it still not working check the delimiters in the where clause (have a look at the AddFieldDelimiters function)
Best Answer
Your question states that you are looking for the "total count of items from field". Yet, you use the max statement and claim that this is what works. Unless the max value in that particular field does indeed match the number of rows, your output isn't for what you are looking.
If you just want the number of entries, it's a simple call to Get Count.
int(arcpy.GetCount_management(lyrfile).getOutput(0))
If that's not what you are looking for @gotchula has a post that will solve the issue efficiently, assuming you are running ArcMap 10.1, and have access to the data access module,
da
.Other than that, there are syntax errors that others have pointed out. Indentation is critical in Python.