Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 596501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:10:42+00:00 2026-05-13T16:10:42+00:00

I’m using python 3.1. Is it possible to create more than 1 docstring for

  • 0

I’m using python 3.1.

Is it possible to create more than 1 docstring for a single module or function?
I’m creating a program, and I’m intending to have multiple docstrings with a category for each. I intend to give other people the program so they can use it, and to make things easy for programmers and non-programmers alike, I’m putting a reference to the docstring for documentation within the program itself.

To be more specific, I have a menu in the program/module as an interface, and one of the options will allow access to the module docstring for documentation on the program. Thus, if it’s possible, I want to make multiple docstrings to categorise different types of documentation. So it would be easier on the users if they want to see some part of the documentation.

eg. first docstring contains instructions on how to use the program. Second docstring contains information on how one part of the program works. Third docstring contains info on how another part works. etc.

Is this possible? And if so, how do you reference them?

Updates: Added a comment.

My original thought was to actually have more than one docstring in the sense of:

def foo():
    """docstring1: blah blah blah"""
    """docstring2: blah blah blah"""
    pass # Insert code here

Then there would be some code that I could use to allow me to reference each of these docstrings.
So, I’m guessing that this isn’t possible then?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T16:10:43+00:00Added an answer on May 13, 2026 at 4:10 pm

    I don’t recommend trying to do something complicated with the docstrings. Best to keep the docstrings simple, and do something else if you want to make a bunch of different documentation options available.

    If you really want to do what you described, I suggest you use tags to delimit sections within docstrings. Like so:

    def foo(bar, baz):
        """Function foo()
    
    * Summary:
        Function foo() handles all your foo-ish needs.  You pass in a bar and a baz and it foos them.
    
    * Developers:
        When you change foo(), be sure you don't add any global variables, and don't forget to run the unit tests.
    
    * Testers:
        When you test foo, be sure to try negative values for baz.
    """
        pass # code would go here
    

    Then you can pretty easily split your string into chunks, and when the user chooses a menu item, show just the appropriate chunks.

    s = foo.__doc__  # s now refers to the docstring
    
    lst = s.split("\n* ")
    section = [section for section in lst if section.startswith("Developers")][0]
    print(section) # prints the "Developers" section
    

    This way, when you are working in the interactive Python shell, you can say “help(foo)” and you will see all the docstrings. And, you are not changing the fundamental behavior of a basic part of Python, which would freak out other people trying to study your code.

    You could also do something even simpler: just make a big global dictionary of docstrings for different purposes, and update it from the source code for each new thing.

    doc_developers = {}
    doc_testers = {}

    def foo(bar, baz):
        """Function foo()
    
    Function foo() handles all your foo-ish needs.  You pass in a bar and a baz and it foos them."
        pass # code goes here
    
    doc_developers["foo"] = "When you change foo(), be sure you don't add any global variables, and don't forget to run the unit tests."
    
    doc_testers["foo"] = "When you change foo(), be sure you don't add any global variables, and don't forget to run the unit tests."
    

    The biggest thing I don’t like about this is that, if you change the name of function foo, you would need to change it in multiple places: once in the actual def and once per dictionary update line. But you could mostly fix that by writing a function:

    def doc_dict = {} # this will be a dict of dicts
    doc_dict["developers"] = {}
    doc_dict["testers"] = {}
    
    def doc_update(fn, d):
        name = fn.__name__
        for key, value in d.items():
            doc_dict[key][name] = value
    
    def foo(bar, baz):
        """Function foo()
    
    Function foo() handles all your foo-ish needs.  You pass in a bar and a baz and it foos them."
        pass # code goes here
    
    d = { "developers": "When you change foo(), be sure you don't add any global variables, and don't forget to run the unit tests.",
    "testers": " When you test foo, be sure to try negative values for baz."}
    
    doc_update(foo, d)
    

    There is probably a way to turn doc_update() into a decorator, but I’m out of time right now.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 302k
  • Answers 302k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer This should work, provided your datetime column is a timestamp… May 13, 2026 at 8:19 pm
  • Editorial Team
    Editorial Team added an answer If you want to share the value across the methods… May 13, 2026 at 8:19 pm
  • Editorial Team
    Editorial Team added an answer Leap seconds. May 13, 2026 at 8:19 pm

Related Questions

I want use html5's new tag to play a wav file (currently only supported
In order to apply a triggered animation to all ToolTip s in my app,
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I've got a string that has curly quotes in it. I'd like to replace

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.