Error debugging in python can sometimes be a frustrating task if you’re not familiar with how to read them and what they mean. My first comment on errors is don’t ignore them. Don’t even ignore warnings. This is common beginner’s mistake when learning a new programming language, or when diving into software development for the first time. In reviewing others’ code, it’s also common for the author of the code suggesting you ignore errors and warnings. Big mistake.
Amazon – WD 8TB Elements Desktop Hard Drive – USB 3.0 – WDBWLG0080HBK-NESN $139.99
In most cases, an error will stop the execution of your python script. Which means that your code will no longer be running. Bummer. But you can prevent this from happening. I know what you’re thinking, try except, ;-). That’s not actually where I was going with this. The best way to prevent errors is to prevent them :-). I have nothing against try except, in fact I use exception handling throughout my code where appropriate, however one thing that I’ve discovered over the years is that most exceptions triggered in python are preventable. As a rule of thumb, use your exception handling to find where the loopholes in your code may be, fix them but leave the exceptions in place in case it happens again.
There are a few common exceptions thrown in python . Syntax error is very common for beginners because you’re learning things for the first time, and of course you’re going to have a hard time making your syntax perfect. Indentation errors is a common one if you’re using a basic text editor to write your python code. If you’re using an IDE, such as PyCharm, it’s very easy to avoid these errors. Value errors occur when an argument is passed to python method that is of the right data type but invalid in value. Import errors occur when you try to import a module and python can’t find it or something else goes wrong. Key Error occurs when you try to access a dictionary key that doesn’t exist. Index Error is similar, in that it is raised when you try to access a list index that doesn’t exist.
If you’d like to see the full list of built in python exceptions, you can check them out here:
https://docs.python.org/2/library/exceptions.html
Amazon – NETGEAR WiFi Range Extender N300 | WiFi coverage up to 300 Mbps (EX2700) $24.71
1 Comment