Hi,
I'm having trouble converting this tool's expression to Python 3, could someone help me?
arcpy.CalculateField_management("selecionado_View", "selecionado_" + Safra + ".SELECIONADO", "[selecionado_" + Safra + ".SELECAO] + [selecionado_" + Safra2 + ".SELECAO]", "VB", "")
I'm not sure what this dot means.
Thank´s
Solved! Go to Solution.
@SoratoSouza_e_Silva wrote:Hi,
I'm having trouble converting this tool's expression to Python 3, could someone help me?
arcpy.CalculateField_management("selecionado_View", "selecionado_" + Safra + ".SELECIONADO", "[selecionado_" + Safra + ".SELECAO] + [selecionado_" + Safra2 + ".SELECAO]", "VB", "")
I'm not sure what this dot means
What the dot means, from the help for Add Join:
In the resulting input table, fields will be prefixed with the input's name and a period (.), and all fields from the join table will be prefixed with the join table name and a period as the default.
Here's a crack at a Python 3 conversion. I second the suggestion in this thread that playing around with the Calculate Field tool interactively would help you learn some of the ins and outs of this, especially if you try Copy as Python command after filling out the tool dialog. A key thing to keep in mind is the python string should be directly interpretable as a Python expression (with the exception of field names surrounded by ! characters) and data types are not converted for you as in VB.
# I am assuming Safra, Safra2 are Python variables of type string.
tbl = "selecionado_" + Safra # ex. selecionado_foo
tbl2 = "selecionado_" + Safra2 # ex. selecionado_foo2
# expr below becomes:
# "!selecionado_foo.SELECAO! + !selecionado_foo2.SELECAO!"
expr = "!{}.SELECAO! + !{}.SELECAO!".format(tbl, tbl2)
arcpy.CalculateField_management("selecionado_View",
tbl + ".SELECIONADO", expr, "PYTHON")
Do you have the ability to generate this query in Pro SelectbyAttribute interface using python selection and then review the SQL query itself with the toggle?
more less I can´t simulate this field:
selecionado_" + Safra + ".SELECIONADO", "[selecionado_" + Safra + ".SELECAO]
This looks like a field concatenation process. Can you list the field names and the data type next to it?
Safra = Text
Safra2 = Text
SELECAO = Text
"selecionado_" just string to concatenate
Thank´s
Performing this exercise in Pro itself, as opposed to just adding it to a script, would be helpful to you to learn the syntax that is required per Dan's replies.
From the links I sent earlier, in Python field names are enclosed in exclamation marks
eg Safra !Safra!
Yes correct but I have problem after of the concatenate: selecionado_" + Safra, Safra = 2122 (Text)
NameError: name 'selecionado_2122' is not defined
@SoratoSouza_e_Silva wrote:Hi,
I'm having trouble converting this tool's expression to Python 3, could someone help me?
arcpy.CalculateField_management("selecionado_View", "selecionado_" + Safra + ".SELECIONADO", "[selecionado_" + Safra + ".SELECAO] + [selecionado_" + Safra2 + ".SELECAO]", "VB", "")
I'm not sure what this dot means
What the dot means, from the help for Add Join:
In the resulting input table, fields will be prefixed with the input's name and a period (.), and all fields from the join table will be prefixed with the join table name and a period as the default.
Here's a crack at a Python 3 conversion. I second the suggestion in this thread that playing around with the Calculate Field tool interactively would help you learn some of the ins and outs of this, especially if you try Copy as Python command after filling out the tool dialog. A key thing to keep in mind is the python string should be directly interpretable as a Python expression (with the exception of field names surrounded by ! characters) and data types are not converted for you as in VB.
# I am assuming Safra, Safra2 are Python variables of type string.
tbl = "selecionado_" + Safra # ex. selecionado_foo
tbl2 = "selecionado_" + Safra2 # ex. selecionado_foo2
# expr below becomes:
# "!selecionado_foo.SELECAO! + !selecionado_foo2.SELECAO!"
expr = "!{}.SELECAO! + !{}.SELECAO!".format(tbl, tbl2)
arcpy.CalculateField_management("selecionado_View",
tbl + ".SELECIONADO", expr, "PYTHON")
Very good! Thank´s @curtvprice help a lot!