Reputation: 348
I want to remove the Jupyter "Run Cell|Run All Cells" buttons that appear if the syntax #%%
is present in Visual Studio Code.
Is there a setting that controls that?
Upvotes: 16
Views: 4201
Reputation: 934
Save the code snippet below as : remove_inline_comment.py
Assuming your filename as : sample_file.py
,
RUN : python remove_inline_comment.py sample_file.py
[ NOTE : Make sure both of these files are in same folder ]
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")
Upvotes: -2
Reputation: 468
Update for others coming to this question:
With recent update you can choose what's displayed Run cell
|...".
If you're looking to remove clutter delete everything and save like below:
I would recommend leaving at least python.datascience.runcell
as it seems to disable shift+enter shortcut
Upvotes: 2
Reputation: 5385
You can toggle off Python>Data Science: Enable Cell Code Lens
settings.
Upvotes: 11
Reputation: 3117
If you turn off the data science features (the Python Interactive window) under Settings>Python>Data Science>Enabled then you won't see those code lenses any more. However that will also hide the rest of the data science features along with the lenses. Were you looking to turn off all data science features in the python extension or just the lenses?
Upvotes: 2