Doctest: Extracts and tests the code that is annotated in the document.
#!/usr/bin/python# -*- coding: utf-8 -*-class dict (Dict): " simple dict but also support access as x.y style. >>> d1 = Dict () >>> d1[' x '] = 100 >>> d1.x 100 >>> d1.y = 200 >>> d1[' y '] 200 >>> d2 = dict (a=1, b=2, c= ' 3 ') >>> d2.c ' 3 '   &Nbsp; >>> d2[' Empty '] Traceback (most recent call last): ... KeyError: ' Empty ' >>> d2.empty traceback (most recent call last): ... AttributeError: ' Dict ' object has no attribute ' empty ' ' def __init__ (self, **kw): super (dict, self). __init__ (**KW) def __getattr__ (Self, key): try: return self[key]&nBsp; except keyerror: raise attributeerror (r "' Dict ' object has no attribute '%s ' " % key) def __setattr__ (self, key, value): self[key] = value if __name__== ' __main__ ': import doctest doctest.testmod ( )
There is nothing out there to prove that the program is correct.
Python Document test: Doctest