Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Renaming a variable everywhere in Jupyter Notebook

Is there a way to rename a variable everywhere in your current jupyter notebook file?

I.e. let's say my notebook referencing a variable "foo" in multiple functions and locations through my script. Later I decide I want to rename this variable to "bar" for better readability...

In xcode, you can highlight and right click to do this. Sort of a smart search/replace command.

Would love to be able to do the same thing.

Thanks!

like image 850
Hazzamataza Avatar asked May 04 '18 14:05

Hazzamataza


People also ask

How do you change the name of a variable everywhere in Python?

The normal keyboard shortcut (including python's IDLE) for this is Ctrl+H , though different editors have different shortcuts. Show activity on this post. In WingIDE you have the option via the Refactor Menu to do Rename Symbol.

How do I set environment variables in Jupyter Notebook?

To set an env variable in a jupyter notebook, just use a % magic commands, either %env or %set_env , e.g., %env MY_VAR=MY_VALUE or %env MY_VAR MY_VALUE . (Use %env by itself to print out current environmental variables.)


2 Answers

I hope you have already solved this. But, my answer will help someone who has similar problem like that. I think this can be accomplished using the Find and Replace option which can be found under the edit menu of the notebook. If you're in command mode, you can easily press the F key and bring up the find and replace dialog. Thank you!

like image 84
Ransaka Ravihara Avatar answered Oct 07 '22 11:10

Ransaka Ravihara


Maybe a bit late, but I found a simple solution:

1 - shift+click in first cell  2 - shift+click in last cell  3 - Press F or go to Edit/Find and Replace  4 - Rename the expression you need. 
like image 32
Alejandro García Avatar answered Oct 07 '22 12:10

Alejandro García