Underline abruptly appears and deletes the code. How can I prevent this? - python

Sometimes when I'm editing python code in Jupyter Notebook, an underline abruptly appears.
I'm trying to edit the code anyway, then the underlined code is deleted when I click it or try to make a selection of some part of the code with Shift button on the keyboard or dragging of the mouse. I tried Ctrl+A to select and copy the whole code but Ctrl+A deleted the whole code.
Actually I don't know what is happening. I don't know exactly how I created the underline or how I deleted the underlined code, hence, I cannot prevent it from happening.
I'm new to Python and Jupyter and trying to use it.
But this has already happened 3-4 times. Please help me.

I had the same issue today and I didn't know why, that's the reason I find this post.
However, I was able to recover with the following method:
1, hold the Crtl + z, not the single click, and the deleted content will be back.
2, once you got everything deleted back, save the notebook and reopen it.

Related

my jupyter notebook is pasting unncessary program lines inbetween

when I try to write any code jupyter notebook automatically paste any irrelevant / sometimes relevant program between the program, but I want to stop this shit, because it is irritating me. suggestions are different things. but this issue has arrived in my notebook for the past few days.you can see in this link exactly what happening in this link
how can I get rid of it? please help me out. The error lines are in green color whereas normal program looks like thisSee this line in grey color is suggested by notebook
I am just confused. I don't know how it started. I didn't get any solution on it anywhere
looks like https://discourse.jupyter.org/t/jupyter-notebooks-annoying-grey-text-auto-show/16886/5, This is most likely a browser issue, what browser are you using? any extentions that could cause this? maybe try switching browsers?

vs code remove white box in editor interface

Basically when I open a file on VScode, a new one or one that I already have, it splits the editor into two, but one half is blank, almost like it was a preview because as I scroll down the code, it follows, but empty....
This "preview blank space" occupies half the screen and it's really bothering me... Could you please help? I think it's a command i have to execute because I've tried to reset the settings and even uninstall the VS code and it stays the same.
It doesn't have any close options (nor the right or left button of the mouse) and I can't move it anywhere (nor open a file on it). Also, I don't think it's editor split because I already did and undo that and it doesn't solve
If anyone knows how to fix it, I would really appreciate because I can't find a solution anywhere and I'm desperate..

Jupyer notebook: Clicked 3 and all output is gone?

Apparently when you type 3 in jupyter notebook the focused cell is turned into markdown and all output is gone, incredible... Now all progress I've done for 20 hours is gone. Any way to fix this? If it's not fixable this is a huge fault in jupyter. No single button should be able to destroy the work like that.
Also in tab-view the cell is still working but nothing inside the document says it is, and I get no output.

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!

iPython Notebook in Firefox - Warning: unresponsive script

I had a long script running on iPython notebook in Firefox for a long time. I came back and it seemed to have hung up, so I saved it and closed it.
When I re-open the script, I get a dialog box pop up with the following error:
Warning: unresponsive script
A script on this page may be busy, or it stack overflow may have
stopped responding. You can stop the script now, open the script in
the debugger, or let the script continue.
The options are 'continue', 'stop script' and 'debug script'. Clicking on any of these leads to the same result, the dialog box disappears and the iPython notebook is unresponsive (for example, ctrl+enter creates a line-break in the current cell rather than executing it).
Worst of all however, the cells at the bottom of the script seem to have been cut off. They contained some valuable code which seems to have gone, this is quite a bad outcome!
I've tried rolling back but the last roll-back point also shows the bottom cut off. Any support here much appreciated!
I have now worked this out and leave it here in the hope it will help others.
The cause of the problem seemed to be an excessively long output from one of the cells - everything below this line had been cut off in the iPython browser, but I discovered it still exists in the .ipynb file and all I had to do was remove some of the output lines, and when I re-opened the file it ran without problems AND my code that had been cut off was available once again.
The notebooks store everything in JSON format. In my case, I needed to remove output from one of the cells, which I did like this:
Browse to your iPython Notebooks directory (NOT where ipython.exe resides) - for me they were in C:\Users\myname\Documents\IPython Notebooks
Right-click on the offending notebook.ipynb file, and edit in a text editor - my choice is Notepad++
Scroll down to the cell which has generated lots of output lines. Each of these lines is inside the cell's outputs property, with "output_type": "stream"
Remove an arbitrary number of these output entries, but be sure to remove anything outside the output property itself, and be sure to remove from the back of a tailing comma to the front of the following comma so that the resulting JSON is well-formed
A typical line of output looks like this, deleting several hundred of them made my script run again in the browser:
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\n",
"Added 150000 records so far"
]
},
Maybe it's Firefox's fault.
Letting the script run longer
If you find that pressing the Continue button brings up the same dialog again, letting the script run longer won't help you; it will just make Firefox hang for longer. However, if you can use Firefox normally after pressing Continue, then the script may just needs extra time to complete.
To tell Firefox to let the script run longer:
In the Location bar, type about:config and press Enter. The about:config "This might void your warranty!" warning page may appear. Click I'll be careful, I promise! to continue to the about:config page.
In the about:config page, search for the preference dom.max_script_run_time, and double-click on it.
In the Enter integer value prompt, type 20.
Press OK.
With scripts now allowed to run for longer times, you may no longer receive the prompt.
This is from https://support.mozilla.org/en-US/kb/warning-unresponsive-script
Hope it could help.

Categories