Arcpy Inline variables

10-22-2014 01:44 PM
New Contributor

I don't use python that often, so hopefully this hasn't been asked 100 times already.

I have a python script created that already contains variables for two tables in a database.  The current python below works fine, but I want to get rid of the paths that are in bold below and replace them with variables.  I have tried deleting the paths and replacing them with the existing variables, but it doesn't appear to work.  I get the correct number of rows added to the second table, but all of the attributes are NULL.  This seems like it should be fairly straight forward, but everything I have tried seems to result in the empty output.  I have tried several options like converting the parameters to strings use the ("%s%s") method but get the same null values.  The only thing that seems to be working is including the full paths.

# Import arcpy module

import arcpy

# Local variables:

Path = "C:\\Users\\Username\\Documents\\ArcGIS\\Default.gdb"

SourceTable = Path + "\\SourceTable"

TargetTable = Path + "\\TargetTable"

# Process: Append

arcpy.Append_management(SourceTable, TargetTable, "NO_TEST", (

"Parcel_ID \"Parcel_ID\" true true false 50 Text 0 0 ,First,#,C:\\Users\\Username\\Documents\\ArcGIS\\Default.gdb\\SourceTable,Parcel_ID,-1,-1;"

"RoadType \"RoadType\" true true false 50 Text 0 0 ,First,#,C:\\Users\\Username\\Documents\\ArcGIS\\Default.gdb\\SourceTable,RoadType,-1,-1", "")

print "Process Finished"

CP modified code formatting

Tags (1)
0 Kudos
1 Reply
MVP Esteemed Contributor

Sorry, I was editing your post to using this guidance and I messed up your bolding.

In general I highly recommend using format() instead of the older %s formatting.

If the path you were trying to replace is inside the field mapping for Append - I'm pretty sure those have to be full paths. In Python scripting if these need to be modified it is normally done using the FieldMappings() and FieldMap() objects and methods, which are complex but very useful once you get the hang of them.

0 Kudos