如何在 PyCharm 中创建部分

How to make section in PyCharm

我刚从 R 转到 Python。在 R 中你可以使用

#new section####

将 'new section' 作为脚本部分列表中的标题。然后,您可以通过点击“跳转到菜单”中的这个标题轻松找到该脚本块(见图)。这张图中,标题是“阅读2013年之前的数据”。

我试图在这里找到我的答案https://confluence.jetbrains.com/display/PYH/Code+folding and here https://www.jetbrains.com/help/pycharm/code-folding.html但是我在折叠方面迷失了,class和....

如何在 PyCharm 中模仿此选项?

更新: 感谢@Robet,我可以通过为每个部分的标题行添加书签(使用 F11)来制作方便的内容。然后我在收藏夹中找到标题。

Using code folding comments

For Python files:

 #region Description
 ...
 #endregion

PyCharm 还允许您设置匿名和标记 bookmarks 来浏览您的源代码。他们的 jump-to 菜单版本是收藏夹 window,您可以使用“查看”菜单显示它:

查看 --> 工具 Windows --> 收藏夹

只是提一下,DeepSpace 链接的有关代码折叠的信息(无法评论 post)在 Jet Brains 网站上的位置已更改,现在是 here

此外,尽管接受的答案解释了如何创建可折叠的代码块,但它没有回答如何在多个块中导航:

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.