ParseFieldName (arcpy)

摘要

Parses a fully qualified field name into its components (database, owner name, table name, and field name) depending on the workspace. ParseFieldName returns a string containing the parsed table name, containing the database, owner, table, and field names separated by commas. The workspace must be a personal, file, or ArcSDE geodatabase.

语法

ParseFieldName (name, {workspace})
参数说明数据类型
name

The field name to be parsed.

String
workspace

Specifies the workspace for fully qualifying the field name. The workspace must be a personal, file, or ArcSDE geodatabase.

String
返回值
数据类型说明
String

Returns the field name parsed into its components (owner name, database name, table name, field name) separated by commas.

代码实例

ParseFieldName example

Returns a fully qualified field name parsed into its components.

import arcpy
import os

# Get the name of the input field and parse it.
#
fieldName = arcpy.GetParameterAsText(0)
arcpy.env.workspace = os.path.dirname(fieldName)

# Create a list and populate it.
#
fullname = arcpy.ParseFieldName(os.path.basename(fieldName))
nameList = fullname.split(",")
database = nameList[0]
owner = nameList[1]
featureclass = nameList[2]

# Qualify the name of the feature class that will be appended to and set
#   the workspace using the administrator's connection.
#
arcpy.env.workspace = "Database Connections/Trans_admin.sde"
AppendFC = arcpy.ValidateTableName("common", "roads")
try:
    if owner == "grace":
        arcpy.CalculateField_management(fullname, "AppendedBy", owner)
        arcpy.Append_management(fullname, AppendFC )
    elif owner == "reed":
        arcpy.CalculateField_management(fullname, "AppendedBy", owner)
        arcpy.Append_management(fullname, AppendFC )
    else:
        arcpy.AddError("Unknown user of input feature class")
except:
    arcpy.AddError(arcpy.GetMessages(2))

相关主题

9/15/2013