1

I am very ill at ease with Python. I am working on ArcGIS 10.3. I am working on a table in a gdb.

I want to fill an empty field of this table with an expression (words) according to the value of a second field in the same table.

In my case, if my second field contain the word "roadway", I want to fill the empty field cells councerned by this expression "route à deux chaussées". I know that accents are not good in programming but I need to fill my field with (french...).

My script is below:

import arcpy

fc = "D:/TESTS_TOP25/POUR_SDC/ROUTIER_TRAITEMENT/DONNEES.gdb"

#field'sname
field1 = "NATURE"
field2 = "symbology"

cursor = arcpy.UpdateCursor(fc)
for row in cursor:
    if field1 == "roadway"
        field2 == "route à deux chaussée"
    cursor.updateRow(row)
  • There are a few errors in your code as posted: you give the path to the geodatabase, but not a feature class in that geodatabase; field2 == isn't the right way to assign the column, but if it were, it would be field2 =; there's no : to follow the if statement; double backslashes are best for Windows paths in Python, or use the os.path module. – Paulo Raposo Nov 24 '15 at 10:28
2

This should do it, using the feature class "UneFC" inside DONNEES.gdb, and using the newer arcpy.da.UpdateCursor().

# -*- coding: utf-8 -*- # Should handle the French characters.

import arcpy

fc = "D:\\TESTS_TOP25\\POUR_SDC\\ROUTIER_TRAITEMENT\\DONNEES.gdb\\UneFC"

fields = ("NATURE", "symbology")

with arcpy.da.UpdateCursor(fc, fields) as cursor:
    for row in cursor:
        if row[0] == "roadway": # if NATURE is "roadway"...
            row[1] = "route à deux chaussée" # Voila votre traduction ;)
        cursor.updateRow(row)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.