![](/img/trans.png)
[英]Visual Studio Code with Jupyter Notebook: Shortcut for “run all”?
[英]Is there a way to remove Jupyter "Run Cell" buttons in Visual Studio Code?
如果 Visual Studio Code 中存在語法#%%
,我想刪除出現的 Jupyter“運行單元|運行所有單元”按鈕。
有沒有控制它的設置?
如果您在 Settings>Python>Data Science>Enabled 下關閉數據科學功能(Python 交互窗口),那么您將不會再看到這些代碼鏡頭。 然而,這也將隱藏其他數據科學功能以及鏡頭。 您是要關閉 python 擴展中的所有數據科學功能還是只關閉鏡頭?
將下面的代碼片段另存為: 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.