howto redirect and extend help content ?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Stef Mientki

    #1

    howto redirect and extend help content ?

    I'm making special versions of existing functions,
    and now I want the help-text of the newly created function to exists of
    1. an extra line from my new function
    2. all the help text from the old function

    # the old function
    def triang(M,sym=1) :
    """The M-point triangular window. <== old help text
    """
    ....

    # the new function
    def chunked_triang( M):
    """ Chunked version of "triang" <== the extra line
    """
    >>help(chunked_ triang)
    # should give something like

    chunked_triang( M) <== the new definition
    Chunked version of "triang" <== the extra line
    The M-point triangular window. <== old help text

    Is that possible ?


    thanks,
    Stef Mientki
  • karoly.kiripolszky

    #2
    Re: howto redirect and extend help content ?

    maybe you should make use of the objects' __doc__ attribute which
    holds the appropriate docstring. try to append something to it in the
    constructor. :)

    more on this in the manual:



    On Jan 28, 4:58 pm, Stef Mientki <S.Mientki-nos...@mailbox. kun.nl>
    wrote:
    I'm making special versions of existing functions,
    and now I want the help-text of the newly created function to exists of
    1. an extra line from my new function
    2. all the help text from the old function
    >
    # the old function
    def triang(M,sym=1) :
    """The M-point triangular window. <== old help text
    """
    ....
    >
    # the new function
    def chunked_triang( M):
    """ Chunked version of "triang" <== the extra line
    """
    >
    >>help(chunked_ triang)
    # should give something like
    >
    chunked_triang( M) <== the new definition
    Chunked version of "triang" <== the extra line
    The M-point triangular window. <== old help text
    >
    Is that possible ?
    >
    thanks,
    Stef Mientki

    Comment

    • Rob Wolfe

      #3
      Re: howto redirect and extend help content ?

      Stef Mientki <S.Mientki-nospam@mailbox. kun.nlwrites:
      I'm making special versions of existing functions,
      and now I want the help-text of the newly created function to exists of
      1. an extra line from my new function
      2. all the help text from the old function
      >
      # the old function
      def triang(M,sym=1) :
      """The M-point triangular window. <== old help text
      """
      ....
      >
      # the new function
      def chunked_triang( M):
      """ Chunked version of "triang" <== the extra line
      """
      >
      >>help(chunked_ triang)
      # should give something like
      >
      chunked_triang( M) <== the new definition
      Chunked version of "triang" <== the extra line
      The M-point triangular window. <== old help text
      >
      Is that possible ?
      You can take advantage of the decorator syntax:
      >>def triang(M,sym=1) :
      .... """The M-point triangular window.
      .... """
      .... return "triang"
      ....
      >>help(triang )
      Help on function triang in module __main__:

      triang(M, sym=1)
      The M-point triangular window.
      >>def add_doc(f):
      .... def wrap(g):
      .... g.__doc__="chun ked version of %s\n%s" % (f.__name__,f._ _doc__)
      .... return g
      .... return wrap
      ....
      >>@add_doc(tria ng)
      .... def chunked_triang( M):
      .... return "chunked triang"
      ....
      >>help(chunked_ triang)
      Help on function chunked_triang in module __main__:

      chunked_triang( M)
      chunked version of triang
      The M-point triangular window.

      --
      HTH,
      Rob

      Comment

      • Stargaming

        #4
        Re: howto redirect and extend help content ?

        Stef Mientki schrieb:
        I'm making special versions of existing functions,
        and now I want the help-text of the newly created function to exists of
        1. an extra line from my new function
        2. all the help text from the old function
        >
        # the old function
        def triang(M,sym=1) :
        """The M-point triangular window. <== old help text
        """
        ....
        >
        # the new function
        def chunked_triang( M):
        """ Chunked version of "triang" <== the extra line
        """
        >
        >>help(chunked_ triang)
        # should give something like
        >
        chunked_triang( M) <== the new definition
        Chunked version of "triang" <== the extra line
        The M-point triangular window. <== old help text
        >
        Is that possible ?
        >
        >
        thanks,
        Stef Mientki
        Don't you think your users can follow this easy reference theirselves?

        Comment

        • Stef Mientki

          #5
          Re: howto redirect and extend help content ?

          >I'm making special versions of existing functions,
          >and now I want the help-text of the newly created function to exists of
          <snip>
          >
          Don't you think your users can follow this easy reference theirselves?
          My public consist of physicians with some knowledge of MatLab.
          I'm trying to give them a system (based on Python) for which no knowledge of Python is needed.
          When they put the cursor on the name of a function (in some pre-processing language, preferably
          something like LabView), the help text will be shown automatically in a separate window,
          without typing any commands.

          cheers,
          Stef Mientki

          Comment

          Working...