1

I try to run code in Spyder and get an error like this. But I ran the code successfully in the Spyder in Anaconda enter image description here

Jing Liao
  • 23
  • 4
  • 2
    There is no code in your image. Just an error message. – David Erickson Jan 07 '21 at 04:25
  • Please edit your question to contains some of your code. We don't want to see thousands and thousands of lines of code, but 40 or 50 lines is okay. Find the part of your code which generates the error message. Copy and paste that snippet onto stackoverflow.com – Toothpick Anemone Jan 07 '21 at 04:29

1 Answers1

0

It varies, but a key error is usually caused when you try to index into a container, and the index is not valid.

duck = {
    'a': 11
    'b': 22
    'c': 33
}
# Note that 'd' is  *NOT* a key into the dictionary..    


print(duck['a']) # VALID
print(duck['b']) # VALID
print(duck['c']) # VALID
print(fuck['d']) # INVALID.... WRONG... BAD... DO NOT DO THIS
# There is no element having index 'd'

If you get a KeyError, it means that something inside of square-brackets [] is wrong.
You probably passed an invalid index into a container.

Toothpick Anemone
  • 4,290
  • 2
  • 20
  • 42