关于Pycharm块注释无法使用的问题
Manny

我们在使用Pycharm写 python 代码的时候会发现,块注释不管从菜单还是快捷键都是无法使用的。上网查了一下原因贴在这里:

https://stackoverflow.com/a/42710582

The Code | “Comment with Block Comment” stays grayed out if pycharm does not know the syntax for adding comments for the particular file type. You can configure this in File | Settings, then select Editor/File Type. Select the Recognized File type that you want to configure comments for, or add it if it does not exist.

简而言之,就是Pycharm不知道 python 文件块注释的语法,所以不能使用。

根据答主所说,你可以根据想要的文件类型进行配置注释。但Pycharm选中已有的File Type后,实际上是不能够编辑的。因此这种方式行不通。

那么要想使用块注释,有以下方案:

  • 选中之后行注释( Ctrl + / ),快速对每行进行注释。
  • 手动使用 ''' 或者 """进行包裹。
  • 新建一种File Type,自定义它的block comment,显然太过繁琐。
  • 使用Live Template代码模板(推荐)

新建代码模板:

image

Template Text:

1
2
3
'''
$START$
'''

这样就可以使用 abbreviation+Tab 键快速生成块注释了。

但Python应该是习惯于使用 # 作为注释,所以第一种方案就挺好的。我作为一个初学者,本文只是给出一个解决方案。

 评论