Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display IPython variables without entering using whos

Is there a way to view a list of the IPython variables currently in the workspace without having to send the command 'whos'. I often find myself not remembering what variable names I want to use while typing a command.

In IPython, I have to erase the current line I was typing and send a 'whos' statement to see which variables are currently available. Normally, in GUI based tools like MATLAB I would just look to the right at my Workspace Variable window.

like image 994
Christopher Dorian Avatar asked Aug 16 '12 16:08

Christopher Dorian


People also ask

Why are there so many variables in my iPython notebook?

Most of the variables are added by IPython and relate to command history, so if you run this sample with the default interpreter, there won’t be quite as many variables present. Also, some functions load up at startup (and you can configure IPython to load others as well).

How to inspect interactive variables in Jupyter/IPython?

Jupyter/IPython provide three helpful magics for inspecting variables. First, there is %who. With no arguments it prints all the interactive variables with minimal formatting. You can supply types to only show variables matching the type given. The %who_ls magic does the same thing, but returns the variables as a list.

How to configure a class in IPython?

Run the conda package manager within the current kernel. This magic exposes most of the IPython config system. Any Configurable class should be able to be configured with the simple line: Where value will be resolved in the user’s namespace, if it is an expression or variable name.

How do I view the state of a cell in IPython?

Now once a cell with the above Python code has been executed, I can inspect the state of my current session by either executing a single cell with one of the variables, in it, or using the IPython display function. A cell will display the value of the last row in the cell (unless you append a ; at the end of the line).


4 Answers

As others said, you can have as many frontends as you like on the same Ipython kernel, i.e 2 command windows for one kernel for example. If you are using the Qt console, shortcuts can get you close to what you want.

Start a second tab with the same kernel with Ctrl+Shift+T. Then you just write your code on the first tab, and, when you need the output of whos, press Ctrl+PageDown to get to the other tab, and you can run whos without deleting your code in the first tab.

like image 174
gg349 Avatar answered Oct 22 '22 13:10

gg349


This isn't a direct answer, but may be useful to you anyway. At least on the system I'm on,

Ctrl-a will position the cursor at the beginning of the line

Ctrl-k will 'kill' the line (think cut)

type whos

Ctrl-y will 'yank' the line as it was back (think paste)

These are emacs keybindings, BTW, and show in many places like Bash and anywhere that uses the readline library.

like image 37
daemacles Avatar answered Oct 22 '22 13:10

daemacles


You can have as many IPython frontends as you like on a single IPy kernel, so yes, if you wanted another front end you could do that, but it seems heavy-handed. Can you not use IPython Notebook?

like image 41
Carl Smith Avatar answered Oct 22 '22 14:10

Carl Smith


Are you asking if you can access the variables of IPython from another instance of the shell?

Because the way it is now, you have a single command window where you interact with the shell by issuing commands, so unlike MATLAB there is no other window to view additional information, so I don't see how this would be possible unless you have another instance of IPython somehow accessing the information from your current shell.

So the answer would seemingly be no.

(If it is somehow possible to do this, I'll be just as happy as you to find out though)

like image 43
Levon Avatar answered Oct 22 '22 12:10

Levon