AddFieldDelimiters (arcpy)
Resumen
Adds field delimiters to a field name to allow for use in SQL expressions.
The field delimiters used in an SQL expression differ depending on the format of the queried data. For instance, file geodatabases and shapefiles use double quotation marks (" "), personal geodatabases use square brackets ([ ]), and ArcSDE geodatabases don't use field delimiters. The function can take away the guess work in ensuring that the field delimiters used with your SQL expression are the correct ones.
Sintaxis
AddFieldDelimiters (datasource, field)
Parámetro | Explicación | Tipo de datos |
datasource |
The field delimiters are based on the data source used. | String |
field |
The field name to which delimiters will be added. The field does not have to currently exist. | String |
Tipo de datos | Explicación |
String |
Returns a delimited field name. |
Ejemplo de código
AddFieldDelimiters example
import arcpy
field_name = arcpy.GetParameterAsText(0)
arcpy.env.workspace = arcpy.GetParameterAsText(1)
in_features = arcpy.GetParameterAsText(2)
out_feat_class = arcpy.GetParameterAsText(3)
state_value = arcpy.GetParameterAsText(4)
# AddFieldDelimiters will return a field name with the proper
# field delimiters for the workspace specified.
#
sql_exp = """{0} = '{1}'""".format(
arcpy.AddFieldDelimiters('c:/data', field_name),
state_value)
# Use delimited field for Select tool SQL expression
#
arcpy.Select_analysis(in_features, out_feat_class, sql_exp)
Temas relacionados
4/26/2014