Python 2.7 Python 2.7,打印文档字符串(文档注释)时出现问题”;函数没有属性“u doc”;错误
我正在研究LPTHW ex 41,其中我们修改了一组打印语句,使用docstring样式,然后使用runner打印它们 代码最初是这样的:Python 2.7 Python 2.7,打印文档字符串(文档注释)时出现问题”;函数没有属性“u doc”;错误,python-2.7,docstring,Python 2.7,Docstring,我正在研究LPTHW ex 41,其中我们修改了一组打印语句,使用docstring样式,然后使用runner打印它们 代码最初是这样的: Function() Print "Several lines of printed material" 修订后,功能开始: Function() """doc comment""" 运行程序将所有函数(“文件室”)连接起来,目的是打印文档注释,而不是打印命令 ROOMS = { 'death': death, 'central_corridor': c
Function()
Print "Several lines of printed material"
修订后,功能开始:
Function()
"""doc comment"""
运行程序将所有函数(“文件室”)连接起来,目的是打印文档注释,而不是打印命令
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'
有人能告诉我如何打印文档注释吗?谢谢 注意到文档需要两个下划线。固定的
_doc_
__doc__
注意,doc需要两个下划线。固定的
_doc_
__doc__