Python Forum
calling a method for a docstring
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
calling a method for a docstring
#1
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?
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
print(myfunction.__doc__)
Output:
None
What is the purpose?
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
that's just an example.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#4
I think the question remains: why do you want to do this?
Reply
#5
to modify the content the way that method does.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#6
And why do you want to do that? Can you not just set the value of __doc__?
Reply
#7
are you going to keep asking why until you hear my life story?
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#8
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.
Reply
#9
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.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  a longer docstring Skaperen 8 1,657 Aug-25-2022, 11:21 PM
Last Post: Skaperen
  NameError when calling a class method mfreudenberg 2 2,300 Sep-25-2020, 07:40 AM
Last Post: mfreudenberg
  calling on a method from one class into another class which is not a child NABA 5 2,810 Apr-29-2020, 07:49 PM
Last Post: deanhystad
  get docstring to work with another block of text at the top Skaperen 4 2,443 Dec-28-2019, 10:37 PM
Last Post: Skaperen
  ptpython docstring metulburr 4 4,470 Nov-17-2017, 01:36 AM
Last Post: metulburr
  calling Class method inside the Class definition tkj80 1 3,711 Jan-23-2017, 04:15 AM
Last Post: Mekire

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020