Skip to content

Instantly share code, notes, and snippets.

@tonjadwyer
Created September 28, 2017 03:52
Show Gist options
  • Save tonjadwyer/0faa6e5939fee0784a1c6ee7742c4556 to your computer and use it in GitHub Desktop.
Save tonjadwyer/0faa6e5939fee0784a1c6ee7742c4556 to your computer and use it in GitHub Desktop.
Get expression and codeblock from .cal file as strings.
def expression_code_block_from_cal(infile):
with open(infile, "rb") as data:
text = data.read().decode('utf-16-le')
lines = text.splitlines()
# trim the trailing spaces
trimmed_lines = []
for line in lines:
trimmed_lines.append(line.rstrip())
filter(None, trimmed_lines)
n = trimmed_lines.index("__esri_field_calculator_splitter__")
function = trimmed_lines[n+1]
expression = r"\n".join(trimmed_lines[:n-1])
print_msg("Function: " + function)
print_msg("Expression: " + expression)
return [function, expression]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment