【发布时间】:2019-08-18 21:41:20
【问题描述】:
如果 Visual Studio Code 中存在语法 #%%,我想删除 Jupyter“运行单元|运行所有单元”注释。
是否有控制它的设置?
谢谢。
【问题讨论】:
标签: python visual-studio-code jupyter-notebook
如果 Visual Studio Code 中存在语法 #%%,我想删除 Jupyter“运行单元|运行所有单元”注释。
是否有控制它的设置?
谢谢。
【问题讨论】:
标签: python visual-studio-code jupyter-notebook
如果您在 Settings>Python>Data Science>Enabled 下关闭数据科学功能(Python 交互窗口),那么您将不会再看到这些代码镜头。然而,这也将隐藏其他数据科学功能以及镜头。您是要关闭 python 扩展中的所有数据科学功能还是只关闭镜头?
【讨论】:
"jupyter.enableCellCodeLens": false
将下面的代码 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")
【讨论】: