簡體   English   中英

有沒有辦法刪除 Visual Studio Code 中的 Jupyter“運行單元”按鈕?

[英]Is there a way to remove Jupyter "Run Cell" buttons in Visual Studio Code?

如果 Visual Studio Code 中存在語法#%% ,我想刪除出現的 Jupyter“運行單元|運行所有單元”按鈕。

VSC

有沒有控制它的設置?

您可以關閉Python>Data Science: Enable Cell Code Lens設置。

設置截圖

如果您在 Settings>Python>Data Science>Enabled 下關閉數據科學功能(Python 交互窗口),那么您將不會再看到這些代碼鏡頭。 然而,這也將隱藏其他數據科學功能以及鏡頭。 您是要關閉 python 擴展中的所有數據科學功能還是只關閉鏡頭?

其他人提出這個問題的更新:

通過最近的更新,您可以選擇顯示的內容Run cell |..."。如果您想消除混亂,請刪除所有內容並保存如下:

在此處輸入圖像描述

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

將下面的代碼片段另存為: 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")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM