is it "legal" to pace the module's doc string after some imports?

Discussion in 'Python' started by Stef Mientki, Oct 26, 2008.

  1. Stef Mientki

    Stef Mientki Guest

    hello,

    I wonder if it's "legal" to pace the module's doc string after some
    imports ?

    I mean something like this:

    from language_support import _
    __doc__ = _(0, """
    some documentation
    """

    thanks,
    Stef Mientki
     
    Stef Mientki, Oct 26, 2008
    #1
    1. Advertisements


  2. Doc strings are normal objects like anything else, so the above should
    work fine.

    The only "magic" that happens with doc strings is that if you have a bare
    string immediately after a class, method or function definition, or at
    the top of the module, it gets picked up by the compiler and assigned to
    __doc__. You can do anything you like to it.


    You might even do this:

    # top of module
    """This is some
    documentation
    blah blah blah
    """

    try:
    from language_support import _
    __doc__ = _(0, __doc__)
    except ImportError:
    pass


    and it should just work.
     
    Steven D'Aprano, Oct 26, 2008
    #2
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.