Python Document test: Doctest

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.