[EMAIL PROTECTED] wrote: > I want to keep track of the number of different exception happens in > my python program: > > ErrorHash = {} > > try: > > # come code ... > > except Exception, e: > print e > errcode = e > > if (ErrorHash.has_key(errcode)): > ErrorFailNo = ErrorHash[errcode] > > ErrorHash[errcode] = ErrorFailNo + 1 > > else: > ErrorHash[errcode] = 1 > > > But when i print out the ErrorHash like this: > > print ErrorHash > > i get an empty string. Can you please tell me how can I put an > Exception as the key of a hash table ? Or how can i dump out all the > content of the hashtable. > > Thank you.
Apparently, the Exception class's __str__() method doesn't print anything about the exception. That doesn't mean the exception is an empty string though: ErrorHash = {} try: raise ValueError except Exception, e: print "the exception is:", e, "<----" if (ErrorHash.has_key(e)): ErrorFailNo = ErrorHash[e] ErrorHash[e] = ErrorFailNo + 1 else: ErrorHash[e] = 1 print ErrorHash -- http://mail.python.org/mailman/listinfo/python-list