init inside def

2010-10-25 Thread targetsmart
Hi, today I just came across a python code snippet where __init__ was defined inside a function.. I am not able to understand the reason why The code snippet was similar like def func1(a,b): def __init__(): func2(a,b) def func2(a,b): if a == b: return True else: return

dumping generator

2010-08-09 Thread targetsmart
Right now if I want to dump the contents of a generator object I use , a snip from a bigger block of code.. try: while gen: print gen.next() except StopIteration: print "Done" else: raise is there a much simpler way ? like for printing list we do list = range(10) print list would print [0, 1

Compare two nested dictionaries

2010-07-25 Thread targetsmart
Hi, I am trying to compare two nested dictionaries, I want to know what is the exact difference between them. I tried this solution ... s1 = set(result1) s2 = set(result2) print s1 - s2 but it doesn't seem show any difference, but assert result1 == result2 fails could so