获得一个似乎没有多大意义的错误.

sil*_*das 3 python debugging dictionary pdb

我一直收到一个错误,它在代码中引用了我的一个词典.但我似乎无法找到导致问题的任何事情.有些东西可能会滑过我的眼睛,但是这里是命令行pdb的错误.

为了解释发生了什么,这是一个相当大的字典,它告诉我这给程序一个'语法错误:无效语法'.在告诉我什么时,箭头没有多大意义......再次引用这是pdb的结果.

distinctiveFeatures = ({1:'Beak',2:'Blood-Drenched',3:'Boiling or Steaming B
ody',4:'Constantly Shedding',5:'Distinctive Markings',6:'Elongated Neck',7:'Hood
',8:'Expanded bone Structure',9:'Albino',10:'Eye Stalks',11:'Glowing Eyes',12:'H
air',13:'Horns',14:'Lizard-Like Fin',15:'Fish-Like Fin',16:'Icy or Cold Body',17
:'Illusionary Features',18:'Metal-Like Features',19:'Multiple Arms',20:'Multiple
Heads',21:'Antlers',22:'Multiple Legs',23:'Multiple Eyes',24:'Stinger',25:'Odor
',26:'On Fire',27:'Oozing Sores',28:'Plant Features',29:'Prehensile Tongue',30:'
Pulsating Skin',31:'Faces',32:'Rocklike Features',33:'Rubber boned',34:'Rubbery
Body',35:'Scales',36:'Serpent Appendages',37:'Shade Form',38:'Shambling Gait',39
:'Shell',40:'Shimmering Body',41:'Skeletal Appearance',42:'Slimy',43:'Speech',44
:'Suction Cups on Limbs',45:'Tail',46:'Tentacles',47:'Transparent',48:'Unusual C
olor',49:'Weapons for Hands',50:'Wet or Drenched Body'51:'Wings',52:'Mechanical
Features',53:'Multiple Features',54:'Special'})



                                                       ^
Run Code Online (Sandbox Code Playgroud)

Win*_*ert 7

在51之前缺少逗号.

将来,为了帮助追踪这种错误,它有助于不将所有内容放在一条巨线上,将它分成几行.这样箭头会更有帮助.

  • @silentjudas,推进入.您可以在字典定义中的任何位置放置空格.我会在每个逗号之后添加换行符. (2认同)