clear_output / stdin issue in python (Python Jupyter Notebook) - python

I am trying to make a makeshift interface to implement human annotation. I made a for loop and the logic is shown as below:
clear_output()
print out the text I need to read
_ append input() result into a list
continue
The problem I encountered is that:
usually the first loop never has any problem, but after a few loops the standard input will just vanish and then the loop stuck.
I don't feel like my code is having any problem, and this error occurs sometimes (especially when the text become long)... but I wanted to eliminate this issue.
Note: This error only shows in Jupyter notebook but not colab.
In this image only the text shows up but not the input box

Related

VS code notebook output

sometimes if my output is too long I am not able to open it in text editor. Normally I used to change code to print in loop, but its too tedious to do this every time. Is there some option to change it?
didnt found any option in vs code
enter image description here
You can search notebook.output.textLineLimit in settings.
You can modify the number here:

How to control result size when using jupyter on vsc and how to search for words in result

I'm currently using Jupytor Notebook on VSC. I found it very uncomfortable when very long result come out because I have to scroll down a long way to go the the next cell, like shown in the picture.
So I was wondering if there is a way to make the result like the original Jupyter Notebook, where they have a separate scroll for the result as shown below.
As an additional question, anyone know how to search for certain words in the result on VSC? ctrl+f only searches for words in the coding cells and not the result.
A work around for the scroll wheel if you don’t want to collapse the code is to add a print statement to the beginning and end of the code block as mentioned in Collapse Output in VS Code Jupyter Into Scrollable Window. I have not been at my computer to test this and this post is from a year ago, so I’m not sure if this solution is still working. EDIT: This solution is no longer working keep an eye on the linked issue for the resolution.
This was also brought up as an issue on GitHub and it was closed saying they have no plans to work on it currently.
#118117
As for the searching in outputs, this is an open issue currently on GitHub: #94239
Scrollable output regions would be handled in VS Code core. This function has not been decided on GitHub at present
For your additional question, I think the filter feature in the search widget might be what you're looking for - you can include outputs with that.

Jupyter Lab, can you stop a cell from showing output in it every time?

So I have been using Spyder for Python, but I end up writing a lot of comments, and the idea of being able to write text in my code without having to comment it out was intriguing to me, so I started trying Jupyter Lab.
I like the cells and whatnot, but I don't want to have the output of my code shown in a new cell below the cell in which I wrote the code. I added an output view pane on the right-hand side, and that shows my output. That's all I want. I don't want it shown in the left-hand pane under the code cell.
However I can't find any way to stop this from happening. I can collapse the unwanted output cell, but then the next time I run my code, it pops up again.
So in the image below, I do want to see all the "{http.." lines on the right, but NOT on the left under the code block.
Any help would be appreciated!! Thanks.

In Jupyter notebook, can the "enable scrolling" window auto-scroll down to keep up pace with the output?

I often write functions that print a lot, say every 100th go-around a long loop, which in the Terminal run fine, because my screen auto-scrolls down with the output; but on Jupyter, the output quickly moves downward, and I have to scroll down myself to keep up with it. This happens whether I'm in the "enable scrolling" or "disable scrolling" for the output.
So, my Q is: Is there a way to have Jupyter auto-scroll down with the output? I suppose this would make more sense inside of a scroll window (i.e. "enable scrolling".) Auto-scrolled output would give a more Terminal-like experience, which I am much more familiar and comfortable with. (And, to be honest, I also miss my The-Matrix-like aesthetic of streaming output.)
If it matters, I use Jupyter Lab primarily, but I believe the same is true on Jupyter Notebook.
Thanks so much, all!
nbextensions has an auto-scroll extension to do just that, though its incompatible with jupyter lab at the moment.
https://jupyter-contrib-nbextensions.readthedocs.io/en/latest/nbextensions/autoscroll/README.html

Ipython Notebook: Elegant way of turning off part of cells?

In my ipython notebook, there is part of cells that serves as preliminary inspection.
Now I want to turn it off, since after running it I know the status of the dataset, but I also want to keep it, so other people using this notebook can have this functionality.
How can I do it? Is there any example of doing it?
I can comment out these cells, but then switching between on and off would be quite laborious. And may not be quite convinent for other people.
I can abstract it into a function, but that itself has some methods, so the code would be quite convoluted, and may be hard to read?
Using Jupyter notebook you can click on a cell, press esc and then r. That converts it to a "raw" cell. Similar thing can be done to convert it back, esc + y. No comments needed, just key presses.
Within Jupyer notebook, go to Help -> Keyboard shortcuts for more.
Here's a snippet:
Command Mode (press Esc to enable)
↩ : enter edit mode
⇧↩ : run cell, select below
⌃↩ : run cell
⌥↩ : run cell, insert below
y : to code
m : to markdown
r : to raw
In Jupyter notebooks one can use this magic preamble at the beginning of a cell to avoid its execution:
%%script false --no-raise-error
You can use a condition at the cost of one extra indentation.
cellEnabled = 0
#cellEnabled = 1
if cellEnabled:
doA()
doB()
I had the same kind of desire and I eventually found out about the nbextension called Freeze. When you enable it, you get a nice freeze button in your toolbar. When you click it, the cell you're currently in will become "frozen". This means it will turn green (making it visually clear) and it will be ignored by the Run All process. It's also locked for editing, so you do need to unfreeze it (unlock button, two over to the left of the freeze button) before editing or running the cell. That's really easy to do though because it's just one button.
Let me know if this wasn't super clear. Otherwise, I hope this helps!

Categories