Hello world! Let's talk about python 🐍
Whether you are a beginner or an advanced python developer, it is a good habit to check your code frequently (while writing, deploying or refactoring). You might wonder, where to start or how to start, here some ideas to check your python code 🐍💻
But first, recall about good code! 🤓 High-quality code should do what's meant to do (functionality), should not have problems or other errors, and should be easy to read and maintain.
✅ your python code should be easy to read for others (First checkpoint!)
There are different tools, that can help you check your python code. I'll mention a few of them, that I've been trying:
Pylint supporting with Coding standards, Error detection, Refactoring help, among others.
Pytest helps you write better programs
Although, both can help you write good coding, also check these general remarks that will guide you in your regular checkings:
Check spaces ✅
Coding on python? spaces are super important! Remember to use whitespaces after a colon, semicolon, or comma, as well as when using operators (it is a good practice!) to have a whitespace ' ' before and after an operator (=, <, >, etc).Booleans ✅
Avoid repetitions... if you are writing this:
var flag = TRUE
# something something
if flag == TRUE
#something
Consider in better writing this:
var flag = TRUE
# something something
if flag
#something
- Handling errors ✅ If writing this...
try:
#something something
except:
Consider writing this...
try:
#something something
except TypeError:
We can go on and on, talking about recommendations to have a high-quality python code! I recommend checking out pytest and/or pylint and see how much better you are getting at coding in python 🤓 and also if you would like to automate and learn more about common errors and best practices, check Code Inspector helping to build code better, faster.
Top comments (1)
Great article Code Inspector!
Here's an article about python static analysis tools we hope it adds value to your readers.
Keep on with great articles!