Hello All, I am having an issue with lists and am not sure where to go from here any advice appreciated. I colored the areas of concern. blue my comments purple example of output red area area concerned theoretically written not tested Sorry if its messy still a newbie. Thanks in advance! Lynn # Import native arcgisscripting module import arcgisscripting, sys, string, os, math # Create the geoprocessor object gp = arcgisscripting.create(9.3) gp.overwriteoutput = 1
# Check out any necessary licenses gp.CheckOutExtension("spatial") # Load required toolboxes... gp.AddToolbox("C:/Program Files (x86)/ArcGIS/ArcToolbox/Toolboxes/Spatial Analyst Tools.tbx") gp.AddToolbox("C:/Program Files (x86)/ArcGIS/ArcToolbox/Toolboxes/Conversion Tools.tbx") gp.AddToolbox("C:/Program Files (x86)/ArcGIS/ArcToolbox/Toolboxes/Data Management Tools.tbx") gp.workspace = "D:\model" # Table and field name inputs inTable = "D:\model\Files.mdb\Last" inPath="D:\model\Path.lyr" inField = "PATH" PRField = "PR" # Variables ECOAG = "D:\\model\\Files.mdb\\ECOAG" # Eco Ag combined with con statment t= string.Template("D:\\model\\Files.mdb\\T$Num") p = string.Template('"PATH" = $Path') prow = string.Template('"PR" = $PRow') wrs_season_shp="D:\model_workspace\wrs_season.shp" wrs_season_Layer="wrs_season_Layer" Files_mdb = "D:\\model\\Files.mdb" paths = gp.SearchCursor(inTable) path = paths.Next() # Create an empty list PathList = [] while path: # If the value is not already in the list, append it if path.GetValue(inField) not in PathList: PathList.append(path.GetValue(inField)) path = paths.Next() # Sort the list alphanumerically PathList.sort() print PathList[0] print PathList logfile=open('listfile.txt', 'w') logfile.write (str(PathList)) logfile.write('goodbye') This is the area that I am having complications with I am getting the correct output at the end of print PRList however because of the loop it overwrites the list each time. Ultimately I need to get a PR list of evens and odds but when I put the EVEN Odd Check in the loop it will only calculate the first even number then give an error. Traceback (most recent call last): File "C:\Users\lwood\Desktop\MODEL SCRIPTS\E\oddeven.py", line 65, in <module> if PR.GetValue(PRField) not in PRList: AttributeError: 'int' object has no attribute 'GetValue' There are 233 paths and within each a different number of rows. I need a list to make a feature layer of just odds and of evens per each path. It works fine when it is out of the loop but only gives me the last path list. I realize that this it is looping over the list each time and that is why the output is for the last path only. I would just like it all in one loop is possible but not necessary. I'm not sure but what I have thought may work is writing the list to a file and appending it each time then reopenning it for the calculations but that seems a little much. Perhaps a Mapping technique or dictionary? Or like I mentioned before it would be fine to do it all in one loop as well. for path in PathList: gp.MakeFeatureLayer_management(wrs_season_shp, wrs_season_Layer,p.substitute(Path = str(path)), Files_mdb,) print path gp.savetolayerfile("wrs_season_Layer", "Path.1yr") PRS = gp.SearchCursor(inPath) PR = PRS.Next() PRList = [path] while PR: # If the value is not already in the list, append it if PR.GetValue(PRField) not in PRList: PRList.append(PR.GetValue(PRField)) PR = PRS.Next() # Sort the list alphanumerically PRList.sort() print PRList This is part of the output each path is listed first then each row within it and if I call PRList[5] is works fine as well 233008 it begins with [1,1001,1002] etc until this is the last output [233, 233005, 233006, 233007, 233008, 233009, 233010, 233011, 233012, 233013, 233014, 233015, 233016, 233017, 233018, 233050, 233051, 233052, 233053, 233054, 233055, 233056, 233057, 233058, 233059, 233060, 233061, 233062, 233063, 233064, 233065, 233066, 233067, 233068, 233069, 233070, 233071, 233072, 233073, 233074, 233075, 233076, 233077, 233078, 233079, 233080, 233081, 233082, 233083, 233084, 233085, 233086, 233087, 233088, 233089, 233090, 233091, 233092, 233093, 233094, 233095] #Even Odd Check for PR in PRList: if PR%2==0: print "Evens" print PR if PR%2>0: print "Odds" print PR Odds 233 Odds 233005 Evens 233006 Odds 233007 Evens etc What I need the list for is here to enter each even or odd PR as a string for a SQL selection such as this I have not written yet but I figure it would work something like this...... for path in PathList: for PR in PRList[path]: if PR%2==0: print "Evens" ##for calculation ## gp.MakeFeatureLayer_management(wrs_season_shp, inPath, prow.substitute(PRow = str(PR[1]or PRow = str(PR[2] etc....)
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor