【问题标题】:Is there a way to remove Jupyter "Run Cell" syntax in Visual Studio Code?有没有办法在 Visual Studio Code 中删除 Jupyter“运行单元”语法?
【发布时间】:2019-08-18 21:41:20
【问题描述】:

如果 Visual Studio Code 中存在语法 #%%,我想删除 Jupyter“运行单元|运行所有单元”注释。

是否有控制它的设置?

谢谢。

【问题讨论】:

    标签: python visual-studio-code jupyter-notebook


    【解决方案1】:

    您可以关闭Python>Data Science: Enable Cell Code Lens 设置。

    【讨论】:

      【解决方案2】:

      如果您在 Settings>Python>Data Science>Enabled 下关闭数据科学功能(Python 交互窗口),那么您将不会再看到这些代码镜头。然而,这也将隐藏其他数据科学功能以及镜头。您是要关闭 python 扩展中的所有数据科学功能还是只关闭镜头?

      【讨论】:

      • 感谢您的回复。我只是想转动镜头(如果这就是所谓的)。只是'运行单元|运行所有细胞的标志。
      • 对不起,Domen,目前没有办法只关闭镜头。如果您愿意,可以在我们的 GitHub 上提出问题:github.com/Microsoft/vscode-python/issues。就个人而言,对于那些不希望文件中出现视觉混乱的人来说,这似乎是一个合理的选择。
      • 曾经有一种方法可以做到这一点……现在我找不到了。我没有看到您所说的设置>Python 数据科学功能,您能详细说明一下吗?
      • 找到了! "jupyter.enableCellCodeLens": false
      【解决方案3】:

      其他人提出这个问题的更新:

      通过最近的更新,您可以选择显示的内容Run cell |..."。 如果您想消除杂乱,请删除所有内容并保存如下:

      我建议至少留下python.datascience.runcell,因为它似乎禁用了 shift+enter 快捷方式

      【讨论】:

        【解决方案4】:

        将下面的代码 sn-p 保存为:remove_inline_comment.py
        假设您的文件名为:sample_file.py,
        运行:python remove_inline_comment.py sample_file.py

        [注意:确保这两个文件都在同一个文件夹中]

        import argparse
        import os
        import sys
        import re
        
        
        def process(filename):
            """Removes empty lines and lines that contain only whitespace, and
            lines with comments"""
        
            with open(filename) as in_file, open(filename, "r+") as out_file:
                for line in in_file:
                    if re.match("# In\[[0-9\\d+\]]", line):
                        out_file.write("\n")
                    else:
                        out_file.writelines(line)
        
        
        if __name__ == "__main__":
        
            my_parser = argparse.ArgumentParser(
                description="Removing the In#\[[0-9\d+\]] in notebook to script conversion"
            )
        
            my_parser.add_argument(
                "script_path",
                metavar="path",
                type=str,
                help="path to script that requires a conversion",
            )
        
            args = my_parser.parse_args()
            script_path = args.script_path
        
            file_format = script_path.split(".")[1]
            if file_format != "py":
                print("File is not a py file")
                sys.exit()
        
            try:
                print(f"processing : {script_path}")
                process(script_path)
            except FileNotFoundError:
                print("Please provide path correctly")
        

        【讨论】:

          猜你喜欢
          • 2023-01-13
          • 1970-01-01
          • 1970-01-01
          • 2018-02-07
          • 2015-07-27
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2016-03-17
          相关资源
          最近更新 更多