0

I open my Python scripts on JupyterLab and make some changes if required. And I need to save changes using written command in my script. Something that will immitate CTRL+S command and do update my local file with all the changes.

Does anybody know how to handle this situation?

1

2 Answers 2

1

There are some python modules to handle this situation for you(like keyboard and PyAutoGUI ). but they are not built-in python and first of all you have to install them using pip install command(you have to have admin privilege to install them). but if you want to save your python script using a command in Jupyter, you can use the following command in a jupyter cell and press Enter:

%%javascript
IPython.notebook.save_notebook()

It will automatically save your changes.

Sign up to request clarification or add additional context in comments.

3 Comments

It gives an error: Javascript Error: IPython is not defined. Any ideas?
I just search this error and found this result for you:link I hope it could solve your problem.
Probably this solutions is OK for %matplotlib widget. Unfortuantely it does not help with %%javascript. :(
0

You can use keyboard module.

import keyboard # Do pip install keyboard if it shows ModuleNotFoundError
#Your code
keyboard.press_and_release('ctrl + s') #Saves the code

6 Comments

There is and error: ImportError: You must be root to use this library on linux.
I am using JupyterLab on corporate server and do not have root access.
@ZaurHuseynov sudo pip3 install keyboard try this when installing the module
I cannot initiate this command because I do not have admin privileges.
@ZaurHuseynov In that case it's not possible to run the keyboard module since you are on a server. There might be a way to do it in Javascript.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.