[Python] Can I format the docstring in Python 3?

Discussão em 'Python' iniciado por Stack, Novembro 27, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to make a docstring that will accept replacement fields as follows

    def run_tests(args):
    """run tests on methods in {0}

    usage: {0} --tests
    """.format(__file__)
    pass


    but when I run help(run_tests) in the interpreter, I do not get the docstring. If I remove {} and .format() the docstring returns as expected.

    I would like to see the output something like:

    Help on function run_tests in module myfile:

    run_tests(args)
    runs tests on methods in myfile.py

    usage: myfile.py --tests


    Is there a way to do this in Python 3?

    Continue reading...

Compartilhe esta Página