0
def display():

    """ i am testing to see doc string  """
    pass

display_1=display()

print(display.__doc__)

output-:i am testing to see doc string

print(display_1.__doc__)

output-:None

Nihal
  • 5,262
  • 7
  • 23
  • 41
ramakrishnareddy
  • 611
  • 1
  • 6
  • 13
  • You assign the return value of your `display()` function to `display_1`. This is None and that does not have a `doc` attribute. Do `display_1=display` – shmee Jul 13 '18 at 06:57

3 Answers3

0

display_1 is not a function. It is None as you have taken the return value of the function display()

What you want to do is this:

display_1 = display

Do not add the () at the end as that will call the function and store the return value in display_1

RohithS98
  • 500
  • 2
  • 14
0

You arr calling to the function display, which has no return. In python, if a function returns nothing explicitly, it returns None.

So, when you are executing display_1=display(), display_1 is None, so it has not the attribute doc

If you want to get the docstring, call display.__doc__

Look at this: Getting the docstring from a function

0

for example you can do like this also:

class DoubleMap(object):
   def __init__(self):
      self.url = "https://someurl"

   def Method(self):
      """rejgnjknkjnklerg"""
      return self.url


mapInstance = DoubleMap.Method.__doc__
print(mapInstance)

in your code display() is no returning any value thats why you are getting none you can do like this if you want

def display():

    """ i am testing to see doc string  """
    return display.__doc__

display_1=display()

print(display.__doc__)
print(display_1)
Nihal
  • 5,262
  • 7
  • 23
  • 41