-- coding: utf-8 -- import arcpy import os import sys reload(sys) sys.setdefaultencoding('utf-8') def check_feature_class_fields(workspace, output_file): def write_warning_to_file(warning_message): with open(output_file, 'a') as f: f.write(warning_message + '\n') arcpy.env.workspace = workspace feature_classes = arcpy.ListFeatureClasses() unqualified_count = 0 field_count = {} for feature_class in feature_classes: feature_class_path = os.path.join(workspace, feature_class) fields = arcpy.ListFields(feature_class_path) field_names = [field.name for field in fields] with arcpy.da.SearchCursor(feature_class_path, ["OID@"] + field_names) as cursor: for row in cursor: oid = row[0] for i, value in enumerate(row[1:], start=1): if value is None or value == "": field_name = field_names[i - 1] warning_message = "Unqualified Feature Class: {} | Field Name: {} | Feature OID: {}".format( feature_class, field_name, oid ) arcpy.AddWarning(warning_message) write_warning_to_file(warning_message) unqualified_count += 1 if field_name in field_count: field_count[field_name] += 1 else: field_count[field_name] = 1 # Write the total count of unqualified cases to the output file. with open(output_file, 'a') as f: f.write("Total Unqualified Cases Found: {}\n".format(unqualified_count)) f.write("Field-wise Unqualified Case Count:\n") for field_name, count in field_count.items(): f.write("Field: {} | Count: {}\n".format(field_name, count)) workspace = arcpy.GetParameterAsText(0) output_file_path_txt = "unqualified_data.txt" check_feature_class_fields(workspace, output_file_path_txt) 检查上述代码是否使用Python 2语言
时间: 2024-02-14 19:19:19 浏览: 144
是的,上述代码使用的是Python 2语言。其中,reload(sys)和sys.setdefaultencoding('utf-8')在Python 3中已经不再需要,而在Python 2中是为了解决编码问题而使用的。而print函数在Python 2中是不需要加括号的,而在Python 3中则需要加上括号。
阅读全文