I've spent quite a bit of time looking at all the similar issues on GeoNet and Stack Exchange but I still can't find an answer. I'm sure that someone will be quick to say that I should use a cursor, but this exact same code works in ModelBuilder just fine!
Is there the potential for a carriage return or something? I copied and pasted my codeblock so that might be a possibility. Here's my code (the FC in question does indeed have a field called 'BEARING'):
<SPAN class="comment token"># Add Quandrant Bearing Field</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>AddField_management<SPAN class="punctuation token">(</SPAN>BoundSplit<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"Q_BEARING"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"TEXT"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">""</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">""</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">""</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">""</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"NULLABLE"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"NON_REQUIRED"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">""</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Calculate Quadrant Bearing</SPAN>
expression <SPAN class="operator token">=</SPAN> <SPAN class="string token">""" DD_DMS_Line(!BEARING!,{0}) """</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>correction<SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>AddMessage<SPAN class="punctuation token">(</SPAN>expression<SPAN class="punctuation token">)</SPAN>
codeblock <SPAN class="operator token">=</SPAN> <SPAN class="string token">"""def DD_DMS_Line(bearing, correction=0):
value = bearing + correction
if value <= 90:
numb = value
prefix = "N"
suffix = "E"
elif value > 90 and value < 180:
numb = 180 - value
prefix = "S"
suffix = "E"
elif value >= 180 and value < 270:
numb = value - 180
prefix = "S"
suffix = "W"
elif value > 270 and value <= 360:
numb = 360 - value
prefix = "N"
suffix = "W"
elif value > 360:
numb = value - 360
prefix = "N"
suffix = "E"
degrees = int(numb)
submin = abs( (numb - int(numb) ) * 60)
minutes = int(submin)
subseconds = abs((submin-int(submin)) * 60)
notation = prefix + str(degrees) + u"\u00b0" + str(minutes) + "\'" +\
str(subseconds)[0:5] + "\"" + suffix
return notation"""</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>CalculateField_management<SPAN class="punctuation token">(</SPAN>BoundSplit<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"Q_BEARING"</SPAN><SPAN class="punctuation token">,</SPAN> expression<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"PYTHON"</SPAN><SPAN class="punctuation token">,</SPAN> codeblock<SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>My expression appears to be fine (highlighted in this image).

ugh, been banging my head against the wall on this one!