【问题标题】:Python 2.7, trouble printing docstrings (doc comments) "function has no attribute _doc_" errorPython 2.7,打印文档字符串(文档注释)“函数没有属性_doc_”错误
【发布时间】:2017-11-06 22:10:57
【问题描述】:

我正在研究 LPTHW ex 41,我们修改了一堆打印语句以使用文档字符串样式,然后使用运行器来打印它们。

代码原本是这样的:

Function()
Print "Several lines of printed material"

修改,功能开始:

Function()
"""doc comment"""

跑步者像这样连接所有功能(“房间”),目标是打印 doc cmets 而不是打印命令。

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')

但我不断收到错误

'function" object has no attribute '_doc_'

样板间:

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'

谁能告诉我如何让文档 cmets 打印?谢谢!

【问题讨论】:

    标签: python-2.7 docstring


    【解决方案1】:

    Notified doc 需要两个下划线。固定

    _doc_
    
    __doc__
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-09
      • 1970-01-01
      • 2010-12-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多