def docformat(docstring, docdict=None):
 if (not docstring):
  return docstring
 if (docdict is None):
  docdict = {}
 if (not docdict):
  return docstring
 lines = docstring.expandtabs().splitlines()
 if (len(lines) < 2):
  icount = 0
 else:
  icount = indentcount_lines(lines[1:])
 indent = (' ' * icount)
 indented = {}
 for (name, dstr) in docdict.items():
  lines = dstr.expandtabs().splitlines()
  try:
   newlines = [lines[0]]
   for line in lines[1:]:
    newlines.append((indent + line))
   indented[name] = '\n'.join(newlines)
  except IndexError:
   indented[name] = dstr
 return (docstring % indented)

def docformat ( docstring , docdict = None ) : if ( not docstring ) : return docstring if ( docdict is None ) : docdict = { } if ( not docdict ) : return docstring lines = docstring . expandtabs ( ) . splitlines ( ) if ( len ( lines ) < 2 ) : icount = 0 else : icount = indentcount_lines ( lines [ 1 : ] ) indent = ( ' ' * icount ) indented = { } for ( name , dstr ) in docdict . items ( ) : lines = dstr . expandtabs ( ) . splitlines ( ) try : newlines = [ lines [ 0 ] ] for line in lines [ 1 : ] : newlines . append ( ( indent + line ) ) indented [ name ] = '\n' . join ( newlines ) except IndexError : indented [ name ] = dstr return ( docstring % indented )
fill a function docstring from variables in dictionary adapt the indent of the inserted docs parameters docstring : string docstring from function .