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

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Sat Oct 25 21:09:04 EDT 2008


On Sun, 26 Oct 2008 02:31:01 +0200, Stef Mientki wrote:

> 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
> """


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



More information about the Python-list mailing list