Document Python Functions with Dostrings

1. addition of self-documentation to your own module

2. provide an example of a function fetching words from an URL

import sys
from urllib.request import urlopen
def fetchwords():
""" Fetch a list of words from URL """
story = urlopen("http://sixty-north.com/c/t.txt")
story_words = []

3. tools

4. Example

def fetchwords():
"""Fetch a list of words from URL.

Args:
url: The URL of UTF-8 text document

Returns:
A list of strings containing words from the document
"""
>>> from words import *
>>> help(fetchwords)
Help on function fetchwords in module words:
fetchwords()
Fetch a list of words from URL.
Args:
url: The URL of UTF-8 text document
Returns:
A list of strings containing words from the document

5. list used sources

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store