How do I edit a jupyter notebook cell's tags in visual studio code? - visual-studio-code

I am editing a .ipynb file in Visual Studio Code, with the file open in VS code's Jupyter Notebook editor.
When I edit this notebook in the Jupyter Notebook App (i.e. if I were not using VS code, instead using the interface described here), I could add tags to cells by clicking View > Cell Toolbar > Tags, and then entering tags into the UI that comes up.
Is there an equivalent way to do this in VS Code?
I am aware I can reopen the file in a text editor view and edit the JSON directly. But I am looking for something a bit more user friendly than this.

Try installing this jupyter on vs code.
On my old windows 7 I used to use this. It has the same interface as when you open Jupiter in your browser but you don't need to load a bunch of stuff to open jupyter. You can open it in one single click like changing text file while writing code inside vc code.
Also you need to install one library to use it but unfortunately I can't remember the library as I don't use python or Jupiter anymore.

In the documentation is a python code cell which enables to change all the cell tags.
import nbformat as nbf
from glob import glob
# Collect a list of all notebooks in the content folder
notebooks = glob("**/*.ipynb", recursive=True)
notebooks_windows = []
for i in notebooks:
j = i.replace("\\", "/")
notebooks_windows.append(j)
notebooks_windows
# Text to look for in adding tags
text_search_dict = {
"# HIDDEN": "remove-cell", # Remove the whole cell
"# NO CODE": "remove-input", # Remove only the input
"# HIDE CODE": "hide-input" # Hide the input w/ a button to show
}
# Search through each notebook and look for the text, add a tag if necessary
for ipath in notebooks_windows:
ntbk = nbf.read(ipath, nbf.NO_CONVERT)
for cell in ntbk.cells:
cell_tags = cell.get('metadata', {}).get('tags', [])
for key, val in text_search_dict.items():
if key in cell['source']:
if val not in cell_tags:
cell_tags.append(val)
if len(cell_tags) > 0:
cell['metadata']['tags'] = cell_tags

Microsoft have finally released an extra extension to support this.
ms-toolsai.vscode-jupyter-cell-tags
See this long running github.com/microsoft/vscode-jupyter issue #1182 and comment recently closing the issue.
Be ware however, that while you can set tags, e.g. raises-exception, which is meant to make the runtime expect and ignore the exception and keep on running more cells, but the vscode-jupyter extension that runs the cells does not always honor tag features the same way that the standard Jupyter notebook runtime does, and so, disappointingly, it's still difficult to demo common mistakes or what not to do (exceptions).

Just copy everything in .py file with the unremovable tags, paste that into a plaintext file. The tags are now just editable text. Remove them, Save As or copy/paste back to the .py file.

Related

How can I make Visual Studio Code suggest tab-completions for any previous line in the file?

I want visual studio code to suggest an autocompletion for an entire line if I start typing the first few characters of any line already in the file, regardless of the content of the existing line. So if this is the content of my file:
this is a line with whitespace
this,is,a,comma,separated,list
And I type this on a new line, I would get a pop-up like any other autocomplete suggestion and I could fill in either of the lines above. How can I do this (and if I can't, is there another editor that has this ability)?
The extension Line Completion does what you want.
You have to configure for which files (language identifiers) it should perform these suggestions. (To prevent to much calculation on large files where you don't use it. See the README page.

Pascal extension on VSCODE (pascal auto indent)

I'm trying to use pascal on vscode and i had to download some extensions, one of them ('Pascal formatter) what me to config this variables:
Indicates the engine app path (required)
"pascal.formatter.enginePath":
Indicates the configuration file for the selected engine (optional)
"pascal.formatter.engineParameters":
But im on ubuntu and i dont know where is that, bc the enginepath default its "C:\FPC\2.6.4\bin\i386-win32\ptop.exe". what i need to do here?
I want to use this extension because vscode its not auto-indenting my code while i write it.
If i write this in vscode :
program example;
var
i:integer;
begin
i:=4;
i:=4+5;
end.
but i want the code to autoindent while im writing like this:
program example;
var(*after hit enter it autoindent*)
i:integer;
begin(*after hit enter autoindent*)
i:=4;
i:=4+5;
end.(*detect end and get it to the same indent than begin*)

Sublime Text 3: Auto-Complete uses incorrect syntax for for loop

With sublime text 3, the autocomplete when typing "for" and hitting tab gives you:
for x in xrange(1,10):
pass
However, this is not a valid statement for python 3. I've tried creating a new build system using the following:
{
"cmd": ["c:/Python37/python.exe", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python"
}
the auto-complete for for still gives the wrong syntax. any advice?
The short version is that the sublime-build and sublime-snippet files that ship with Sublime in support of Python target Python version 2 and not Python version 3. I don't know if that's just due to that being what was used initially or if it's being done on purpose, though.
In Sublime, resources are generally related to a particular language based on the scope provided by the syntax definition. So for example snippets for Python are associated with source.python, your example build file uses that scope to know that it applies to Python files, and so on. As such, no matter what build you happen to be using, that has no effect on the snippets that are being offered.
By way of example, if you use the View Package File command from the command palette and enter the text python for snippet, the list of package resources will filter to Python/Snippets/for.sublime-snippet; pressing Enter to view that resource shows this:
<snippet>
<tabTrigger>for</tabTrigger>
<scope>source.python</scope>
<description>For Loop</description>
<content><![CDATA[
for ${1:x} in ${2:xrange(1,10)}:
${0:pass}
]]></content>
</snippet>
Here the tabTrigger specifies how the snippet inserts, scope controls where it inserts and content controls what it is inserts. Thus, in order to change it to support Python 3, you need to either create your own snippet or modify the existing one.
An issue with creating your own snippet is that it will be added to the list of snippets including the offending one, which allows it to possibly still trigger when you don't expect it to. There is also no general purposes "easy" way to disable individual snippets.
As such, generally the best course of action would be to use the PackageResourceViewer package. Install it, select PackageResourceViewer: Open Resource from the command palette, then select the same file as outlined above and modify the content of the snippet (e.g. replace xrange with range) and save the file.
That will get Sublime to replace the existing snippet with your edited version, so that it takes the place of the existing one and works the way you want.

Editor does not recognize some characters

When I open a cobol file in Notepad++ it looks normal. However, in Visual Studio Code it looks weird like it does not recognize the characters in it. How can I make it so that it looks normal in Visual Studio Code also.
Here is how it looks in both.
Notepad++
Visual Studio Code
It's probably saved in an encoding besides UTF-8. You can change the encoding with the "Change File Encoding" command, or by clicking on the encoding in the status bar. Or, try setting "files.autoGuessEncoding": true.
Put a call to the built-in input function
at the very bottom of the script in 3.X (in 2.X use the name raw_input instead). For example:
import sys # Load a library module
print(sys.platform)
input() # <== ADDED
input reads and returns the next line of standard input, waiting if there is none yet available. The net effect in this context will be to pause the script, thereby keeping the output window open until you press the Enter key

ipython notebook # find and replace has only replace "all" option

How to selectively replace some words in a single cell e.g. there are 7 variables named 'foo', and replace 3 of them by 'moo'.
The ipython notebook gives only option of replace all.
Update
The version 6.1.1 of the notebook server does not all address this issue. However, I have shifted to Jupyter Lab 2.1.5, which allows selective replacement.
It looks as if it is not possible as of today.
Here's what one of the contributers says on the subject:
I am opposed to trying implement that in our current UI - it doesn't
have the needed abstractions to do that well. In the new
JupyterLab/Workbench it will be quite easy to build a find/replace UI
in a separate panel that allows us to toggle the individual
replacements while still showing the notebook (in a non-model way).
https://github.com/jupyter/notebook/issues/558#issuecomment-164180866