Created
September 28, 2017 03:52
-
-
Save tonjadwyer/0faa6e5939fee0784a1c6ee7742c4556 to your computer and use it in GitHub Desktop.
Get expression and codeblock from .cal file as strings.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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