MCPcopy Create free account
hub / github.com/ipython/ipython / whos

Method whos

IPython/core/magics/namespace.py:353–476  ·  view source on GitHub ↗

Like %who, but gives some extra information about each variable. The same type filtering of %who can be applied here. For all variables, the type is printed. Additionally it prints: - For {},[],(): their length. - For numpy arrays, a summary with shape, number

(self, parameter_s='')

Source from the content-addressed store, hash-verified

351 @skip_doctest
352 @line_magic
353 def whos(self, parameter_s=''):
354 """Like %who, but gives some extra information about each variable.
355
356 The same type filtering of %who can be applied here.
357
358 For all variables, the type is printed. Additionally it prints:
359
360 - For {},[],(): their length.
361
362 - For numpy arrays, a summary with shape, number of
363 elements, typecode and size in memory.
364
365 - Everything else: a string representation, snipping their middle if
366 too long.
367
368 Examples
369 --------
370
371 Define two variables and list them with whos::
372
373 In [1]: alpha = 123
374
375 In [2]: beta = 'test'
376
377 In [3]: %whos
378 Variable Type Data/Info
379 --------------------------------
380 alpha int 123
381 beta str test
382 """
383
384 varnames = self.who_ls(parameter_s)
385 if not varnames:
386 if parameter_s:
387 print('No variables match your requested type.')
388 else:
389 print('Interactive namespace is empty.')
390 return
391
392 # if we have variables, move on...
393
394 # for these types, show len() instead of data:
395 seq_types = ['dict', 'list', 'tuple']
396
397 # for numpy arrays, display summary info
398 ndarray_type = None
399 if 'numpy' in sys.modules:
400 try:
401 from numpy import ndarray
402 except ImportError:
403 pass
404 else:
405 ndarray_type = ndarray.__name__
406
407 # Find all variable names and types so we can figure out column sizes
408
409 # some types are well known and can be shorter
410 abbrevs = {'IPython.core.macro.Macro' : 'Macro'}

Callers

nothing calls this directly

Calls 2

who_lsMethod · 0.95
formatMethod · 0.45

Tested by

no test coverage detected