How to use a variable with the function calculate () with ArcGIS API for Python

600
2
Jump to solution
10-31-2018 10:36 PM
explocarto
New Contributor III

calculate(where, calc_expression, sql_format='standard')

lst_country = ["country1","country2","country3"]

for country in lst lst_country:

      update_result = commune_flayer.calculate(where="nom = country", calc_expression={"field": "date_horaire", "value": provinces.attributes['date_horaire']})

Thanks

0 Kudos
1 Solution

Accepted Solutions
explocarto
New Contributor III
'nom = "{}"'.format(country)

It's good I finally found. It was necessary to declare this syntax

"nom = '{}'".format(country)

Thank you

View solution in original post

0 Kudos
2 Replies
Luke_Pinner
MVP Regular Contributor
'nom = "%s"' % country
# or
'nom = "{}"'.format(country)

Look up Python string formatting.  Don't forget you need quotes around string values in where clauses.

explocarto
New Contributor III
'nom = "{}"'.format(country)

It's good I finally found. It was necessary to declare this syntax

"nom = '{}'".format(country)

Thank you

0 Kudos