Counting how many times a point goes through a loop and write the count to a text

I have a several feature classes that go through a loop to calculate points. I want to add up how many go through it each time so I can archive that number. I'm using ArcGIS 10.1. Lets say I have 100 shapefiles with anywhere between 1 - 50 points per shapefile. I want to run a count on the total number of points in those 100 shapefiles. Right now it's printing out the total number of points in each shapefile loop. Is there a way to add the 'count' up to create a total?

SMON = arcpy.ListFeatureClasses("SectMon_PLSS_*")
for fc in SMON:
filename =  "'" + arcpy.env.workspace + os.sep + fc + "'"
arcpy.env.overwriteOutput = True
for fc in SMON:
result = arcpy.GetCount_management(fc)
count = int(result.getOutput(0))
x.append(count)
c = sum(x for x in x)
print "The cumulative sum for this iteration is %s" %c

This is what the printouts are giving me:

P:\Scripts\SystemData\TestData\TO PAM\140306_BCR_PNTS102034-102035&103003-103005 (1).shp
This is located in Colorado North
This is located in Colorado North
This is located in Colorado North
This is located in Colorado North
This is located in Colorado North
Fields Calculated
The cumulative sum for this iteration is 5
P:\Scripts\SystemData\TestData\5pm\140226_BCR_PNTS100463-100465.shp
This is located in North Dakota North
This is located in North Dakota North
This is located in North Dakota North
Fields Calculated
The cumulative sum for this iteration is 3
P:\Scripts\SystemData\TestData\5pm\140311_BCR_PNT100466.shp
This is located in North Dakota North
Fields Calculated
The cumulative sum for this iteration is 1
P:\Scripts\SystemData\TestData\5pm\140312_BCR_PNTS100467-100469.shp
This is located in North Dakota North
This is located in North Dakota North
This is located in North Dakota North
Fields Calculated
The cumulative sum for this iteration is 3
#############NORTH DAKOTA FINISHED################

I want to be able write to a log file each time it goes through a loop. I'm trying this, but it's giving me an error.

txtFile = open(count,"a")
txtFile.write("This is the total amount " + str(c))

It's telling me "coercing to Unicode: need string or buffer, int found"

If you want to get a count of all of the features (e.g. rows) in your point feature class for each iteration, you can use Get Count (Data Management). Then use a generator to count your points on a cumulative basis.

Here would be one way to count your cumulative points for each iteration:

SMON = arcpy.ListFeatureClasses("SectMon_PLSS_*")

x = []
for fc in SMON:
result = arcpy.GetCount_management(Control)
count = int(result.getOutput(0))
x.append(count)
c = sum(x for x in x)
print "The cumulative sum for this iteration is %s" %c
• Where would this go? Below the code? – MjonesGEO Mar 13 '14 at 16:52
• OK, I think I got to the jist of your question. However, your script does not make sense for a few reasons: 1) your for loop is incorrectly indented and 2) you are not using "ControlPoints" at all in the script. – Aaron Mar 13 '14 at 17:09
• Yeah, I just gave a snippet of the code. Control points belong in a different loop. The script is working and adding each point in each feature class. How do I keep a running total of these? – MjonesGEO Mar 13 '14 at 17:11
• Could you please describe what "adding each point in each feature class" means? Does Get Count work for your script? If not, why not? – Aaron Mar 13 '14 at 17:16
• So lets say I have 100 shapefiles with anywhere between 1 - 50 points per shapefile. I want to run a count on the total number of points in those 100 shapefiles. Right now it's printing out the total number of points in each shapefile loop. Is there a way to add the 'count' up to create a total? – MjonesGEO Mar 13 '14 at 17:22