Variable in WhereClause

Discussion created by zJuice on Nov 17, 2011
Latest reply on Nov 17, 2011 by zJuice
I am trying to create mapbooks that only print the pages I need using python. I cannot seem to figure out how to make it use a variable.

import arcpy, os

North = r"\\pwapps01\eSRI\ESRI Conversion\Maps\MapBooks\mxd_Final\MapBook1_N.mxd"
fc = r"\\Pwapps01\esri\ESRI Conversion\Maps\MapBooks\Shp\Book_1.shp"
mxdPathLeft = North
tempMapLeft = arcpy.mapping.MapDocument(mxdPathLeft)
tempDDPLeft = tempMapLeft.dataDrivenPages

# Loop creates individual pdf's for odd numbered pages
for pgNumLeft in range(1, tempDDPLeft.pageCount + 1, 2):
[INDENT]whereClause = "PageNumber = pgNumLeft"[/INDENT]
[INDENT]src = arcpy.SearchCursor(fc, whereClause)[/INDENT]
[INDENT]for row in src:[/INDENT]
[INDENT][INDENT]if row.getValue ("InBook") == 0:[/INDENT][/INDENT]
[INDENT][INDENT][INDENT]temp_filename = r"\\Pwapps01\esri\ESRI Conversion\Maps\MapBooks\temp\temp_pdfs\MB_" + str(pgNumLeft) + ".pdf"[/INDENT][/INDENT][/INDENT]
[INDENT][INDENT][INDENT]if os.path.exists(temp_filename):[/INDENT][/INDENT][/INDENT]
[INDENT][INDENT][INDENT][INDENT]tempDDPLeft.exportToPDF(temp_filename, "RANGE", pgNumLeft")[/INDENT][/INDENT][/INDENT][/INDENT]

PageNumber and InBook are fields in my Book_1.shp.

Here is the error I get.

Traceback (most recent call last):
File "Y:\ESRI Conversion\Scripts (ESRI)\MapBook\test", line 13, in <module>
src = arcpy.SearchCursor(fc, whereClause)
File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\__init__.py", line 804, in SearchCursor
return gp.searchCursor(*args)
File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\_base.py", line 357, in searchCursor
RuntimeError: ERROR 999999: Error executing function.
A column was specified that does not exist.
A column was specified that does not exist.

Any help would be greatly appreciated.