Search code examples
python-2.7docstring

Python 2.7, trouble printing docstrings (doc comments) "function has no attribute _doc_" error


I'm working on LPTHW ex 41, where we modify a bunch of print statements to use a docstring style and then use a runner to print them.

The code originally was like this:

Function()
Print "Several lines of printed material"

Revised, the functions begin:

Function()
"""doc comment"""

A runner connects all the functions ("rooms") like so, with the goal being to print doc comments instead of print commands.

ROOMS = {
'death': death,
'central_corridor': central_corridor,
'laser_weapon_armory': laser_weapon_armory,
'the_bridge': the_bridge,
'escape_pod': escape_pod
}


def runner(map, start):

    next = start

    while True:
        room = map[next]
        print "\n----------------"
        print room._doc_
        next = room()

runner(ROOMS, 'central_corridor')

But I keep getting the error

'function" object has no attribute '_doc_'

Example room:

def central_corridor():
"""You wanna blow thing up.
You running toward place for to get bomb.
Emeny approach!

1 = shoot at enemy
2 = avoid emenemeny
3 = use bad pick up line on emenie
4 = hint"""

#print(_doc_)

action = int(raw_input("> "))

if action == 1:
    print "He shoot you first."
    return 'death'

elif action == 2:
    print "No he still gots you."
    return 'death'

elif action == 3:
    print "Oh yeah sexy boy."
    print "You get past laughing enemy."
    return 'laser_weapon_armory'

elif action == 4:
    print "Emeny like good joke."
    return 'central_corridor'

else:
    print "You enter wrong input"
    return 'central_corridor'

Can anyone tell me how to get the doc comments to print? Thanks!


Solution

  • Noticed doc needs two underscores. Fixed

    _doc_
    
    __doc__