示例来源

  1. """This is the docstring for the example.py module. Modules names should
  2. have short, all-lowercase names. The module name may have underscores if
  3. this improves readability.
  4. Every module should have a docstring at the very top of the file. The
  5. module's docstring may extend over multiple lines. If your docstring does
  6. extend over multiple lines, the closing three quotation marks must be on
  7. a line by itself, preferably preceded by a blank line.
  8. """
  9. from __future__ import division, absolute_import, print_function
  10. import os # standard library imports first
  11. # Do NOT import using *, e.g. from numpy import *
  12. #
  13. # Import the module using
  14. #
  15. # import numpy
  16. #
  17. # instead or import individual functions as needed, e.g
  18. #
  19. # from numpy import array, zeros
  20. #
  21. # If you prefer the use of abbreviated module names, we suggest the
  22. # convention used by NumPy itself::
  23. import numpy as np
  24. import matplotlib as mpl
  25. import matplotlib.pyplot as plt
  26. # These abbreviated names are not to be used in docstrings; users must
  27. # be able to paste and execute docstrings after importing only the
  28. # numpy module itself, unabbreviated.
  29. def foo(var1, var2, long_var_name='hi'):
  30. r"""A one-line summary that does not use variable names or the
  31. function name.
  32. Several sentences providing an extended description. Refer to
  33. variables using back-ticks, e.g. `var`.
  34. Parameters
  35. ----------
  36. var1 : array_like
  37. Array_like means all those objects -- lists, nested lists, etc. --
  38. that can be converted to an array. We can also refer to
  39. variables like `var1`.
  40. var2 : int
  41. The type above can either refer to an actual Python type
  42. (e.g. ``int``), or describe the type of the variable in more
  43. detail, e.g. ``(N,) ndarray`` or ``array_like``.
  44. long_var_name : {'hi', 'ho'}, optional
  45. Choices in brackets, default first when optional.
  46. Returns
  47. -------
  48. type
  49. Explanation of anonymous return value of type ``type``.
  50. describe : type
  51. Explanation of return value named `describe`.
  52. out : type
  53. Explanation of `out`.
  54. type_without_description
  55. Other Parameters
  56. ----------------
  57. only_seldom_used_keywords : type
  58. Explanation
  59. common_parameters_listed_above : type
  60. Explanation
  61. Raises
  62. ------
  63. BadException
  64. Because you shouldn't have done that.
  65. See Also
  66. --------
  67. otherfunc : relationship (optional)
  68. newfunc : Relationship (optional), which could be fairly long, in which
  69. case the line wraps here.
  70. thirdfunc, fourthfunc, fifthfunc
  71. Notes
  72. -----
  73. Notes about the implementation algorithm (if needed).
  74. This can have multiple paragraphs.
  75. You may include some math:
  76. .. math:: X(e^{j\omega } ) = x(n)e^{ - j\omega n}
  77. And even use a Greek symbol like :math:`\omega` inline.
  78. References
  79. ----------
  80. Cite the relevant literature, e.g. [1]_. You may also cite these
  81. references in the notes section above.
  82. .. [1] O. McNoleg, "The integration of GIS, remote sensing,
  83. expert systems and adaptive co-kriging for environmental habitat
  84. modelling of the Highland Haggis using object-oriented, fuzzy-logic
  85. and neural-network techniques," Computers & Geosciences, vol. 22,
  86. pp. 585-588, 1996.
  87. Examples
  88. --------
  89. These are written in doctest format, and should illustrate how to
  90. use the function.
  91. >>> a = [1, 2, 3]
  92. >>> print [x + 3 for x in a]
  93. [4, 5, 6]
  94. >>> print "a\n\nb"
  95. a
  96. b
  97. """
  98. pass