Python Forum

Full Version: calling a method for a docstring
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
can i call a method on a docstring?
def myfunction(foo,bar):
    """this is
my docstring for
my function.""".replace('\n',' ')
    return foo+bar
will it recognize that as the docstring?
print(myfunction.__doc__)
Output:
None
What is the purpose?
that's just an example.
I think the question remains: why do you want to do this?
to modify the content the way that method does.
And why do you want to do that? Can you not just set the value of __doc__?
are you going to keep asking why until you hear my life story?
No. The point is to try and understand your goal and not the solution you think you need to achieve it.

I've seen people come up with extremely complicated solutions to problems and then post to ask for help with them. What happens in those cases is that people can go in circles telling them it's a bad idea, or trying to understand what they really want it for.. but no-one really gets anywhere. One particular example I can think of is that the OP had a problem with pickling and type checking and their thread was focussing on that. After going back and forth a while, we did manage to get somewhere: it turned out what they wanted to do was make sure their software still worked after changing it. Had they lead with that goal, we'd have gotten to pointing them to automated testing much more quickly.
i have a docstring. it's not exactly what i want. appending a certain method call to a string like that makes a string that into what i want.

it is my understanding that the first unassigned value in a unit of code (such as a script file, a function, or a class, assigns that str to the __doc__ string for that unit of code. however, when i tried it, __doc__ was None.