How do I avoid KeyError when working with dictionaries?

后端 未结 3 1987
说谎
说谎 2020-12-09 17:08

Right now I\'m trying to code an assembler but I keep getting this error:

Traceback (most recent call last):
  File \"/Users/Douglas/Documents/NeWS.py\", line 44,         


        
3条回答
  •  攒了一身酷
    2020-12-09 17:53

    There is no key 'LD' in registerTable. Can put a try except block :

    try:
       a=registerTable[item]
          ...
    except KeyError:
       pass
    

提交回复
热议问题