Feature Spotlight: Reformatting Python code with Pycharm’s intentions
Happy Friday everyone!
Did you have a chance to read one of my previous posts on how PyCharm helps you write clean and maintainable Python code? As a quick recap: Pycharm highlights code style violations with both PEP8 and custom inspections, and it also allows you to apply automatic quick-fixes to keep your code in consistent format.
Today I’m going to cover another feature that you may find handy for writing professional and quality code. It’s called Code intentions.
The main difference between PyCharm’s code inspections and intentions is that while inspections provide quick-fixes for code that has potential problems, intentions help you apply automatic changes to code that is most likely correct.
Here’s how it works:
When editing absolutely correct code, the yellow bulb sometimes appears in the editor:
That signals that the automatic action is available to be applied in place. To get a list of intentions applicable to the code at the caret, just press Alt + Enter:
In this particular situation PyCharm offers to convert the lambda to a normal function. Just hit Enter and it will do the job for you:
It also highlights the new function name and when you change it, it automatically changes the function call:
Another way to get to the intentions settings or simply disable the unwanted intention is to hit right arrow on the intention in the editor:
I bet you’ll like this feature if you haven’t tried it before.
Have a great weekend and see you next week!
Subscribe to Blog updates
How to Connect Django With MongoDB
Learn how to use Django and MongoDB together to create a web application in PyCharm. Follow our step-by-step tutorial to connect MongoDB with Django.
New Low-Impact Monitoring API in Python 3.12
Python 3.12 adds the new low-impact monitoring API, enabling debuggers, profilers, and similar tools to run code at almost full speed.
Guest Post: Four Ways To Quickly Display OpenCV Images During Debugging
This is a guest blog post by Adrian Boguszewski, author of OpenCV Image Viewer Plugin. The average programmer makes 70 errors per 1,000 lines of code and spends 75% of their time on debugging (source). In computer vision (CV), this process may involve not only fixing the code but also checking th…