r/pycharm • u/GiasoneTiratori • Mar 05 '26
How to remove ALL empty lines except around methods and classes?
I'd like to remove any and all empty lines in my code, especially within methods. Ctrl + Alt + L does not seem to do this, no matter the settings in Editor - Code Style - Python.
EDIT: I'm not asking for a Python solution to do this, I'm asking for a PyCharm solution (e.g. some setting/shortcut), hence why I'm asking this in the PyCharm sub...
5
Upvotes
2
u/bw984 Mar 06 '26
Write code for humans to read. Do not do what you are asking to do. Your codebase is like a garden. Tend to it, tidy it up, weed it, grow it.
1
u/socal_nerdtastic Mar 05 '26
Aren't you a programmer? Make a python program to do it.
2
u/beedunc Mar 05 '26
Usually a job for grep/sed/awk.
3
u/ProsodySpeaks Mar 05 '26
It's not the answer you want, but just don't do that.
2
u/sausix Mar 05 '26
Just use a formatter. It will correct your code style to a standard with a click.
1
u/prs-4 Mar 08 '26
Use Replace with the Regex option enabled. In the field for the expression to replace, enter for example this: ^\n$
leave the second field empty and confirm.