0

I want to use the global doctstring in my command help. This a working example:

"""
This is a global description.

Usage:
    Use it like so::

    $ python my_fancy_script <my_fancy_name>
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

import django.core.management as management

logger = logging.getLogger(__name__)

class Command(management.base.BaseCommand):
    """
    This is a local doc.
    """
    args = '<work_db_name>'
    help = globals()['__doc__']

This feels hacky and I was wondering is there is another way to specifically use the global docstring. Once you do

help = '__doc__' 

the local description, that is, the Command's docstring will be used.

LarsVegas
  • 6,522
  • 10
  • 43
  • 67

1 Answers1

0

Assuming help is Django specific member and you need it (though I never heard of Django to interfere with built-ins),

help = __doc__

Should do the trick, this is essentially the same as globals()['__doc__'] because of looking for __doc__ bubbles up to the module level scope. In the worst case, __doc__ is None, then

help = __doc__ or Command.__doc__

can be used (or something like this).

If not to use help variable I'd go the following way:

""" module doc """
class C: pass
C.__doc__ = __doc__
u354356007
  • 3,205
  • 15
  • 25