Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make section in PyCharm

I have just moved to Python from R. In R you can use

#new section####

to have the 'new section' as title in the script section list. Then, you could easily find that block of script by hitting this title within "Jump to menu" (see figure). In this figure, the title is "reading data before 2013".

enter image description here

I have tried to find my answer here https://confluence.jetbrains.com/display/PYH/Code+folding and here https://www.jetbrains.com/help/pycharm/code-folding.html But I am lost in terms folding, class and....

How can I mimic this option in PyCharm?

Update: Thanks to @Robet, I could make a handy content by bookmarking (using F11) the title lines of each section. I then find the titles in favorites.
enter image description here

like image 779
Seyed Omid Nabavi Avatar asked Mar 14 '19 13:03

Seyed Omid Nabavi


3 Answers

See Using code folding comments

For Python files:

 #region Description
 ...
 #endregion
like image 159
DeepSpace Avatar answered Oct 17 '22 19:10

DeepSpace


PyCharm also allows you to set anonymous and labeled bookmarks for navigating your source code. Their version of a jump-to menu is the Favorites window, which you can display using the View menu:

View --> Tool Windows --> Favorites

like image 35
Robert Avatar answered Oct 17 '22 19:10

Robert


Just to mention that the info concerning Code folding as linked by DeepSpace (can't comment on post) has changed place on Jet Brains website and is now here.

Also, although the accepted answer explains how to create a foldable block of code, it does not answer how to navigate through multiple blocks:

To fold blocks of code, select a code fragment and press Ctrl+Alt+T, from the popup menu select region...endregion Comments. Use Ctrl+Alt+. to navigate to the custom folding block.

like image 1
mikibok Avatar answered Oct 17 '22 18:10

mikibok