dmetzler

calculating the complete path to an attribute

Discussion created by dmetzler on Jan 4, 2013
Latest reply on Jan 11, 2013 by curtvprice
Greetings,
    I have a question that I believe has a simple answer but I just can't quite find it. I am trying to calculate the absolute path of a shapefile to an attribute. so the goal is to have a "shpname" field that has the comple path e.g. C:/desktop/superfunline.shp. here is my python.

def main():
    try:
        import arcpy, sys, traceback, os, glob
        arcpy.env.overwriteOutput = True
        masterFolder = r"Q:\GIS\Field_Data\MT"
        outputFolder = r"C:\tmp\Shp_merged"

        #collect a list of subfolders in master folder
        arcpy.env.workspace = masterFolder
        arcpy.ListWorkspaces('','Folder')
        subfolderLst = arcpy.ListWorkspaces('','Folder')
        print subfolderLst
        for subfolder in subfolderLst:
            arcpy.env.workspace = subfolder
            fcLst = arcpy.ListFeatureClasses()
           
            for fc in fcLst:
                #file = fc in fcLst
                filename = os.path.abspath(__file__)
                print filename
                arcpy.AddField_management(fc, 'shpname','text')
                arcpy.CalculateField_management(fc, 'shpname',filename, "PYTHON" )


    except:
        print arcpy.GetMessages()
        # Get the traceback object  '"' + wildcard + '"'
        tb = sys.exc_info()[2]
        tbinfo = traceback.format_tb(tb)[0]

        # Concatenate information together concerning the error into a
        #   message string
        pymsg = tbinfo + "\n" + str(sys.exc_type)+ ": " + str(sys.exc_value)

        # Return python error messages for use with a script tool
        arcpy.AddError(pymsg)

        # Print Python error messages for use in Python/PythonWin
        print pymsg

if __name__ == '__main__':
    main()



I am thinking the bold is where the error is occuring. the error is:

ERROR 000539: <type 'exceptions.SyntaxError'>: invalid syntax (<expression>, line 1)


Thanks!

Dave

Outcomes