Join field within Python: No output??

627
6
04-25-2012 01:39 PM
AllieHartman
New Contributor
has anyone ever done a join field within Python to produce a join in ArcMap in a attribute table? The join works in ArcMap model builder but does not give us the correct script we are looking to use in PythonWin. We have tried using different extensions and whatnot but some how even when there is an exit code of 0 there is no output within ArcMap. Does anyone have suggestions?  Any hints that could help us identify the problem at hand? Thanks!

this is an example of script as is right now
import arcpy
try:
    from arcpy import env
   
    #set workspace
    env.workspace = "E:\python\Final\Dan"

    #local parameters   
    inFeatures = "aslc940_polygon_Project"
    layerName = "Export_Output_Ashland"
    joinField = "GRID_CODE"
    joinTable = "lulc_gridcode_crosswalk"
    joinField2 = "Code"
    fieldList = "land_cover"

    arcpy.JoinField_management (inFeatures, joinField, joinTable, joinField2, fieldList)

except:
    arcpy.GetMessages(2)
Tags (2)
0 Kudos
6 Replies
DarrenWiens2
MVP Honored Contributor
Try replacing the back slashes in the path to forward slashes.

edit: I just tried it and it works.

second edit: after seeing Phil's post below, I should note that I didn't use the fieldlist parameter in my test - you should use his advice.
0 Kudos
PhilMorefield
Occasional Contributor III

  • It's preferable that you post your example script here using code blocks. There is a sticky post at the top of this forum that explains how to do that.

  • Your value of fieldList is not a list, it's a string. To make a Python list, enclose a string in brackets:
    fieldList = ["land_cover"]

  • As somebody else pointed out, your workspace variable is not being set correctly. This is probably the problem.

0 Kudos
AllieHartman
New Contributor
ive made those changes and i am now trying to run the script in Python. Does it take a long time to run? cause Python has been running the script now for about 10 mins and is still going?
0 Kudos
DarrenWiens2
MVP Honored Contributor
It'll depend on how complicated the join is. Mine finished in about 5 seconds, but I was only joining about 10 features to another 10.
0 Kudos
MathewCoyle
Frequent Contributor
To give you a ballpark, when I join a 900k row feature class to 900k row table with 20 fields it takes about an hour on a pretty beefy workstation.
0 Kudos
AllieHartman
New Contributor
ok thank you for the help!
0 Kudos