2008-09-04 12 views
44

यही है। यदि आप किसी फ़ंक्शन या क्लास को दस्तावेज़ बनाना चाहते हैं, तो आप परिभाषा के ठीक बाद एक स्ट्रिंग डालते हैं। उदाहरण के लिए:मैं पायथन में मॉड्यूल कैसे दस्तावेज़ करूं?

def foo(): 
    """This function does nothing.""" 
    pass 

लेकिन मॉड्यूल के बारे में क्या? मैं कैसे दस्तावेज कर सकता हूं file.py करता है?

+2

देखो, मैं सिर्फ यह मिल गया है: http://docs.python.org/devguide/documenting.html आशा आपके लिए उपयोगी हो। –

उत्तर

36

पैकेज के लिए, आप इसे __init__.py में दस्तावेज़ कर सकते हैं। मॉड्यूल के लिए, आप मॉड्यूल फ़ाइल में बस एक डॉकस्ट्रिंग जोड़ सकते हैं।

सभी जानकारी यहाँ है: http://www.python.org/dev/peps/pep-0257/

4

यह आसान है, आप बस मॉड्यूल के शीर्ष पर एक डॉकस्ट्रिंग जोड़ें।

6

आप इसे ठीक उसी तरह से करना। मॉड्यूल में पहले कथन के रूप में एक स्ट्रिंग रखो।

+0

जब आप कोई नया मॉड्यूल बनाते हैं तो यह ग्रहण स्वचालित रूप से होता है। – Rivka

28

अपने डॉकस्ट्रिंग को first statement in the module के रूप में जोड़ें।

जब से मैं एक उदाहरण देखने जैसा:

""" 
Your module's verbose yet thorough docstring. 
""" 

import foo 

# ... 
2

यहाँ कैसे मॉड्यूल प्रलेखित किया जा सकता पर एक Example Google Style Python Docstrings है। असल में मॉड्यूल के बारे में एक जानकारी है, इसे कैसे निष्पादित किया जाए और मॉड्यूल स्तर चर के बारे में जानकारी और ToDo आइटम्स की सूची है।

"""Example Google style docstrings. 

This module demonstrates documentation as specified by the `Google 
Python Style Guide`_. Docstrings may extend over multiple lines. 
Sections are created with a section header and a colon followed by a 
block of indented text. 

Example: 
    Examples can be given using either the ``Example`` or ``Examples`` 
    sections. Sections support any reStructuredText formatting, including 
    literal blocks:: 

     $ python example_google.py 

Section breaks are created by resuming unindented text. Section breaks 
are also implicitly created anytime a new section starts. 

Attributes: 
    module_level_variable1 (int): Module level variables may be documented in 
     either the ``Attributes`` section of the module docstring, or in an 
     inline docstring immediately following the variable. 

     Either form is acceptable, but the two should not be mixed. Choose 
     one convention to document module level variables and be consistent 
     with it. 

Todo: 
    * For module TODOs 
    * You have to also use ``sphinx.ext.todo`` extension 

.. _Google Python Style Guide: 
http://google.github.io/styleguide/pyguide.html 

""" 

module_level_variable1 = 12345 

def my_function(): 
    pass 
... 
...