Field Calculator '*.cal' file encoding ... not '*.py'

4449
15
06-21-2017 05:01 AM
DanPatterson_Retired
MVP Emeritus

The ability to save and reuse python snippets for using in the Calculate Field tools is useful (aka... the field calculator for non-ArcGIS Pro users).  A couple of questions then...

  • UTF-16-LE .... the encoding used for some reason rather than utf-8 for instance

  • UC2-2 LE BOM ... is this good enough if you use a Notepad++ file?
  • -*- coding: <encoding-name> -*-   as the first line using either the UTF or UC2 version... will that solve encoding problems with the *.cal files?

And the biggie....Why can't you use Python *.py files?

It is more out of curiosity and... I have to teach... so this is what I have to tell my students...

  • the default language used in Pro is Python...
  • Python files have a *.py file extension ...
  • except in the calculate field tool for Pro, 
  • *.cal files is all you will see,
  • save your 'defs' as cal and py files if you want to use them everywhere
  • no more questions now... I have a headache

Some illumination would be useful so I can expand my bullet list.  Others that teach out there, may wish to jump in with addition missives should they have encountered any

Curtis PriceTimothy Hales‌ perhaps, or an FYI##

15 Replies
DanPatterson_Retired
MVP Emeritus

'68 for me, with cards... thanks Vince

0 Kudos
DanPatterson_Retired
MVP Emeritus

Fresh ones arrive... with 10.5.1 more parameters in slope and aspect check geoprocessing section and Pro 2.0 is live

0 Kudos
curtvprice
MVP Esteemed Contributor

The help for 10.5.1 and Pro 2.0 is up, but no software yet for me on my.esri.  Probably very soon though.

This is cool: GPU processing with Spatial Analyst—Help | ArcGIS Desktop 

0 Kudos
DanPatterson_Retired
MVP Emeritus

Wow... 29 viewers, hi to the esri staff that I haven't heard of.  325 emails? must have generated some interest.

BUT

I will close this off as a discussion since it appears that the status quo will remain for some reason (legacy purposes?).

Workarounds abound ... I don't need them, but thank you.  I am more interested in finding a suitable explanations for my students without using

'.... because, that's the way it is... '

in an explanation of why python is widely adopted, except when saving in the field calculator.

Anyone at UC... ask around... 

Dan

0 Kudos
ScottDrzyzga
New Contributor III

Thanks for posting this, for you helped me answer an unrelated question.  I had a student that used a text editor to edit a *.cal file, but on [Load], all the characters had "changed" to Chinese.  We kept trying to fix it by saving to UTF-8 or ANSI, but ... UC2-2 LE BOM.  Thanks.  

While I'm here, has the big question been answered yet?  Not here, obviously, but elsewhere?

"And the biggie....Why can't you use Python *.py files?"

GIS professional and map nerd | Outdoor enthusiast | Remote Pilot (USA and Canada)
0 Kudos
DanPatterson_Retired
MVP Emeritus

It hasn't.... and there is probably some reason beyond 'inertia', that I am not privy to. 

In any event, I just keep two exact same versions, or if I just forget, I change the file extension and comment out the last 2 lines that the *cal version magically adds

__esri_field_calculator_splitter__
angle_between(!Shape!, True)

Those two lines are what populates the Expression box so that the *cal does all the work for you.

0 Kudos