I'd be grateful if someone could help me understand what's happening in the lines I've marked. I can't see how the dictionary is built or how the lists ['bytype'][cytype] make sense in python.
Thanks in advance.
class Stats:
def getContentTypes(self):
""" Returns the number of documents by type """
pc = getToolByName(self, "portal_catalog")
# call the catalog and loop through the records
results = pc() <=== what is the difference between pc and pc()?
numbers = {"total":len(results),"bytype":{},"bystate":{}} <=== This is hard to understand
for result in results:
# set the number for the type
ctype = str(result.Type)
num = numbers["bytype"].get(ctype, 0) <==== where does .get come from? and what is the string 'bytype' doing?
num += 1
numbers["bytype"][ctype] = num <====== is this some kind of an array?
# set the number for the state state = str(result.review_state) num = numbers["bystate"].get(state, 0) num += 1 numbers["bystate"][state] = num return numbers
-- http://mail.python.org/mailman/listinfo/python-list