开发者

Getting an error that doesn't seem to make much sense.

开发者 https://www.devze.com 2023-04-04 04:11 出处:网络
I keep getting an error that\'s referencing one of开发者_Python百科 my Dictionaries in the code. But I can\'t seem to find anything that would be causing the problem. Something is probably slipping pa

I keep getting an error that's referencing one of开发者_Python百科 my Dictionaries in the code. But I can't seem to find anything that would be causing the problem. Something is probably slipping past my eyes, but here's the error from command line pdb anyways.

To explain what's going on, this is a rather large dictionary and it's telling me this is giving the program a 'Syntax Error: Invalid Syntax'. The arrow doesn't make much sense in telling me what.... Keynote again this is the result from 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'})



                                                       ^


Missing comma just before 51.

In future, to help trace this kind of error, its helpful not to put everything on one giant line, split it across several lines. That way the arrow will be more helpful.


Getting an error that doesn't seem to make much sense.

You are missing a comma.

By the way, why do you put the dictionary between brackets? You can do ({ ..},) to make the dictionary the first element of a tuple, or just {..} for a plain dictionary

Using an editor that shows syntax coloring (like e.g. Idle or SciTe) helps a lot.

Because your keys are all integers, perhaps an easier option would be to make a list:

distinctiveFeatures = ['Beak', 'Blood-Drenched', 'Boiling or Steaming Body', 'Constantly Shedding', 'Distinctive Markings', 'Elongated Neck', 'Hood', 'Expanded bone Structure', 'Albino', 'Eye Stalks', 'Glowing Eyes', 'Hair', 'Horns', 'Lizard-Like Fin', 'Fish-Like Fin', 'Icy or Cold Body', 'Illusionary Features', 'Metal-Like Features', 'Multiple Arms', 'MultipleHeads', 'Antlers', 'Multiple Legs', 'Multiple Eyes', 'Stinger', 'Odor', 'On Fire', 'Oozing Sores', 'Plant Features', 'Prehensile Tongue', 'Pulsating Skin', 'Faces', 'Rocklike Features', 'Rubber boned', 'RubberyBody', 'Scales', 'Serpent Appendages', 'Shade Form', 'Shambling Gait', 'Shell', 'Shimmering Body', 'Skeletal Appearance', 'Slimy', 'Speech', 'Suction Cups on Limbs', 'Tail', 'Tentacles', 'Transparent', 'Unusual Color', 'Weapons for Hands', 'Wet or Drenched Body', 'Wings', 'MechanicalFeatures', 'Multiple Features', 'Special']

to get your element:

distinctiveFeatures[0]

gives

'Beak'


Element 50 is missing a trailing comma.

You can simplify this line to debug such errors. Start by removing half of the string between the curly braces.

If the problem persists, continue halving the remainder until you find the tiny piece that caused the error, and correct it.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号