getValue
汇总
Row 对象表示表格的一行。 将从 InsertCursor 、 SearchCursor 和 UpdateCursor 返回 Row 对象。
旧版本:
游标函数和 Row 对象仅供在旧版脚本中使用。 编写或更新脚本时,建议您使用 arcpy.da 模块中的游标。 arcpy.da 游标提供了改进的性能和功能,并支持更新的字段类型和令牌。
讨论
Row 对象动态支持来自数据源的字段名称作为读/写属性。 可以使用 setValue 和 getValue 方法访问无法直接作为属性提供支持的字段名称,例如包含句点的限定字段名称。
语法
getValue()
方法
getValue(field_name)
返回字段值。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
field_name |
The field from which the value will be accessed. |
String |
返回值
| 数据类型 | 说明 |
|---|---|
|
Object |
字段值。 |
isNull(field_name)
指定该字段值是否为空。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
field_name |
The field that will be queried. |
None |
返回值
| 数据类型 | 说明 |
|---|---|
|
Boolean |
如果字段值为空,则为 True。 |
setNull(field_name)
将字段值设置为空。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
field_name |
The field that will be set to null. |
String |
setValue(field_name, object)
设置字段值。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
field_name |
The field that will be set to the new value. |
String |
|
object |
The value that will be used to set the field value. |
Object |
代码示例
可以使用更新游标从要素类中获取行,更新字段值和行,由此迭代游标中的行。
import arcpy
# Set the workspace
arcpy.env.workspace = "c:/data"
# Use row object to get and set field values
cursor = arcpy.UpdateCursor("Addresses.dbf", '"STATENAME" = \'Ariz\'' )
# Iterate through rows and update values
for row in cursor:
row.setValue("STATENAME", "Arizona")
cursor.updateRow(row)
del cursor, row