Create a code section in PyCharm


I have a very quick question:

Is it possible to manually create code sections in python that i can collapse and expand?

In RStudio for example, you can create a section with this syntax:

`### mysection ---- `

It would be really helpful to have someting similar to this in PyCharm. In addition to collapsing of for loops or functions.


Comment actions Permalink

Hello Andrey, I have the same question as the original writer, but unfortunately you did not answer it. Folding a region is not the same as being able to _permanently_ add section markers, which also help navigating in the Structure pane, for example.

Comment actions Permalink

Martin Winter Hi, 

I didn't mention it before, but you can surround multiple lines of code with a fold region comments. Please see

Comment actions Permalink

Andrey Resler Thanks for your reply. This is a bit better, but still does not match what Rider does for C#: The region comments there also appear in the Structure pane, allowing for quick scanning of the file and even for collapsing of regions in the pane (like in an outline). This would help tremendously with larger files that have several groups of topically related methods.


Please sign in to leave a comment.