CalculateField with PYTHON with international settings

3790
6
04-22-2011 03:32 AM
CoDrost
New Contributor II
I tried to calculate an area with:

  gp.CalculateField(fcGFE_Result,'AREA','!SHAPE.AREA!','PYTHON')

When I use the internation settings with a . as decimal separator everything is doing just fine.
But my localsettings are set to ((Dutch_Netherlands)) with a "," as a decimal separator.

The error message I got is:
    gp.CalculateField(fcGFE_Result,'AREA','!SHAPE.AREA!','PYTHON')
arcgisscripting.ExecuteError: ERROR 000539: Error running expression: 304852,037832481 <type 'exceptions.SyntaxError'>: invalid token (<string>, line 1)

When I using the same command within ArcMap I got no problem.

I also tried to set the locale parameters:
  locale.setlocale(locale.LC_ALL, 'C')
and
locale.setlocale(locale.LC_ALL, '')

Is there anybody with a proper solution? Now I am using a workarround, but I am still curious....
Tags (2)
0 Kudos
6 Replies
JasonScheirer
Occasional Contributor III
0 Kudos
CoDrost
New Contributor II
Use locale.atof.


I tried already the locale option:
  gp.calculatefield(fn,'area','locale.atof(!shape.area!)','PYTHON')

gives Error:

  ExecuteError("ERROR 000539: Error running expression: locale.atof(7133,63322549874) <type 'exceptions.AttributeError'>: 'int' object has no attribute 'replace'\nFailed to execute (CalculateField).\n
0 Kudos
JasonScheirer
Occasional Contributor III
gp.calculatefield(fn,'area','locale.atof("!shape.area!")','PYTHON')
0 Kudos
CoDrost
New Contributor II
Thanks, it works!!!

Isn't it posible to disable the international settings when programming with ArcGIS in Python? It is very confusing when ArcMap functionate well with the same command and in a script you need to "locale" the geoprocessing commands...
0 Kudos
JasonScheirer
Occasional Contributor III
Unfortunately due to implementation details, Python doesn't see the ArcMap locale, meaning you essentially have to double-set it, once in ArcGIS and then once again in your Python script.
0 Kudos
DanPatterson_Retired
MVP Emeritus
Is this double-setting being addressed in some release?  It also occurs when using SA tools necessitating that one set environments in any running tools rather than relying on defaults set elsewhere.
0 Kudos