Most distinguish colleagues,
I'm not very good a coding. In fact...I'm a beginner. Yet, I inherited this python script that does compression and analysis and I can't figure out why when we switch from 10.3.1 to 10.6.1 the script won't run anymore. It gives me the following error message:
ERROR: Step1_CompressAnalyze.py: Line 35
ERROR: unsupported operand type(s) for +: 'NoneType' and 'NoneType'
Line 35
dataList = arcpy.ListTables() + arcpy.ListFeatureClasses() + arcpy.ListRasters() # type:
Here is the whole script.
import arcpy def main(parentSDE): import os import sys import datetime if parentSDE == '': parentSDE = arcpy.GetParameterAsText(0) TOOLROOT = os.path.abspath(os.path.dirname(sys.argv[0])).rpartition("\\")[0] tool_folder = os.path.join(TOOLROOT,"ToolData") reportFolder = os.path.join(TOOLROOT,"Reports","Daily") stepName = "Step1_" try: #Delete older logs. map(os.unlink, (os.path.join(reportFolder,f) for f in os.listdir(reportFolder) if stepName in f)) reportFile = os.path.join(reportFolder,"Step1_CompressandAnalyze.txt") logFile = open(reportFile,'a') arcpy.env.workspace = parentSDE print "I've done it!" #1. Find all feature datasets, feature classes, tables fcList = [] unversionedList = [] tableList = [] unversionedTable = [] userName = 'OWNER' print ("Nailed it!") dataList = arcpy.ListTables() + arcpy.ListFeatureClasses() + arcpy.ListRasters() # type: print arcpy.GetMessages() for dataset in arcpy.ListDatasets("", "Feature"): dataList += arcpy.ListFeatureClasses(feature_dataset=dataset) arcpy.RebuildIndexes_management(parentSDE, "SYSTEM", dataList, "ALL") arcpy.AnalyzeDatasets_management(parentSDE, "SYSTEM", dataList, "ANALYZE_BASE", "ANALYZE_DELTA", "ANALYZE_ARCHIVE") print ("Analyze Complete") #2. Compress database logFile.write("\nCompressed:\n") compressTable = os.path.join(parentSDE,[f for f in arcpy.ListTables() if "compress_log" in f.lower()][0]) fieldList = [f.name for f in arcpy.ListFields(compressTable)] arcpy.Compress_management(parentSDE) with arcpy.da.SearchCursor(compressTable,fieldList) as cur: for row in cur: lastRow = ",".join(str(x) for x in row[:]) logFile.write(",".join(fieldList)) logFile.write("\n") logFile.write(lastRow) logFile.write("\n") print ("I've done it the right way!") #3. Analyze last time arcpy.RebuildIndexes_management(parentSDE, "NO_SYSTEM", dataList, "ALL") arcpy.AnalyzeDatasets_management(parentSDE, "NO_SYSTEM", dataList, "ANALYZE_BASE", "ANALYZE_DELTA", "ANALYZE_ARCHIVE") ## Review report for errors errorLogs = [] allLogs = [] for (dirPath,dirName,fileNames) in os.walk(reportFolder): for fileName in fileNames: if stepName in fileName: reportFile = os.path.join(reportFolder,fileName) with open(reportFile) as f: content = [x.upper() for x in f] if "FAILURE" in content or "IN PROGRESS" in content or "UNSUCCESSFUL" in content: errorLogs.append(reportFile) arcpy.AddWarning("Warning or Error found: %s"%reportFile) else: allLogs.append(reportFile) arcpy.SetParameterAsText(1,errorLogs) return (allLogs,errorLogs) except Exception, e: import traceback, sys, os tb = sys.exc_info()[2] arcpy.AddError("%s: Line %i"%(str(os.path.basename(__file__)),tb.tb_lineno)) arcpy.AddError(e) logFile.write("%s: Line %i\n"%(str(os.path.basename(__file__)),tb.tb_lineno)) logFile.write(str(e)) logFile.close() arcpy.SetParameterAsText(1,reportFile) return([],[reportFile]) finally: logFile.close() arcpy.AddMessage("--%s Complete"%(str(os.path.basename(__file__)).replace(".pyc",''))) if __name__ == "__main__": parentSDE = '' main(parentSDE) print "I'm done compressing!"
After I run it I see this message:
I've done it!
Nailed it!
ERROR: Step1_CompressAnalyze.py: Line 35
ERROR: unsupported operand type(s) for +: 'NoneType' and 'NoneType'
--Step1_CompressAnalyze.py Complete
I'm done compressing!
Any help would be much appreciate it. Thank you.
Jennifer
for line numbers... I don't count beyond 5
/blogs/dan_patterson/2016/08/14/script-formatting
a = None
b = None
c = [1,2,3]
a + b + c
Traceback (most recent call last):
File "<ipython-input-43-c4404d400413>", line 1, in <module>
a + b + c
TypeError: unsupported operand type(s) for +: 'NoneType' and 'NoneType'
One solution
d = []
for i in (a, b, c):
if i is not None:
d.extend(i)
d
Out[53]: [1, 2, 3]
Thanks for ya'll responses. What happened was that the arguments within the Task Scheduler were not being read correctly. Also, the task wasn't being completed on the server because it had to be run under a different user name.
All things that a person who originally built this script would have known. However, I didn't because I was still not yet hired.
So for all you who struggle with someone else's work....be certain they create a user name to run tasks. Hopefully, one that doesn't disappear when the person leaves.