Syntax Error

885
2
05-16-2012 10:43 AM
JoelMadero
New Contributor
I'm getting the following error with my code which is generated in excel using a VB script. I am really confused as to what's triggering it:
Parsing error <type 'exceptions.SyntaxError'>: invalid token (line 16)


import arcpy
mxd = arcpy.mapping.MapDocument('CURRENT')
lyr = arcpy.mapping.Layer("EPREC_SEQ")
lyr_1 = arcpy.mapping.Layer("Polls")
df = arcpy.mapping.ListDataFrames(mxd, "2012-06-05")[0]
lyr.definitionQuery = '"CONSNUM" = 135080 or "CONSNUM" = 135220'
lyr_1.definitionQuery = '"CONSNUM_1" = 135080 or "CONSNUM_1" = 135220'
df.extent = lyr.getExtent(True)
var_text = 0176
element_name = "map_ID" 
for elm in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", element_name): 
 if elm.name == element_name:
  elm.text = (var_text)
arcpy.RefreshActiveView()
arcpy.mapping.PrintMap (mxd)
var_text = 0184
element_name = "map_ID" 
for elm in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", element_name): 
 if elm.name == element_name:
  elm.text = (var_text)
arcpy.RefreshActiveView()
arcpy.mapping.PrintMap (mxd)


The error is strange because it's identical code to line 9 which goes through fine. I put in one line at a time and for some reason when I set my var_text to anything above 0177 and anything below 200 I get the error, otherwise the code works fine. Any thoughts?
Tags (2)
0 Kudos
2 Replies
MathewCoyle
Frequent Contributor
You need to put your var_text in quotes so it knows it is a string, otherwise it is trying to write unicode or something funky.
var_text = "0176"
0 Kudos
JoelMadero
New Contributor
You need to put your var_text in quotes so it knows it is a string, otherwise it is trying to write unicode or something funky.
var_text = "0176"


You seem to be the helper of helpers today. Thanks that did the trick. In my last script I never noticed this because var_text was always based on one formula but now it's in an if statement that makes it different depending on the number so I guess unicode screwed it up but problem solved
0 Kudos