Skip to content
/ listvars Public

Python module to print a formatted list of all global variables with additional filtering options.

License

Notifications You must be signed in to change notification settings

szapp/listvars

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

listvars

Python module to print a formatted list of all global variables with additional filtering options.

Installation

Clone listvars into a directory in your python path.

git clone https://github.com/szapp/listvars.git
cd listvars
pip install -r requirements.txt

Usage

A formated table of a filtered list of all global variables is drawn.

>>> from listvars import listvars
>>> listvars()
╭───────┬──────────┬──────┬──────────────────────────────╮
│ NameTypeSizeValue             │
├───────┼──────────┼──────┼──────────────────────────────┤
│     astr34'Long string containing \n…' │
│ arrayfloat64 │ (6,) │             min: 1, max: 3.5 │
│     bint │      │                           42 │
│     cNoneType │      │                         None │
│     ddict2 │     {0: 'Hello', 1: 'World'} │
│  var1str5'hello' │
│  var2str5'world' │
│  var3int │      │                           13 │
│  var4dict2 │   {'key0': 'var0', 'key1': … │
╰───────┴──────────┴──────┴──────────────────────────────╯

Fields

Different columns may be shown by specifying them with the optional fields parameter.

>>> listvars(fields=['name', 'value'])
╭───────┬──────────────────────────────╮
│ NameValue             │
├───────┼──────────────────────────────┤
│     a'Long string containing \n…' │
│ arraymin: 1, max: 3.5 │
│     b42 │
│     cNone │
│     d │     {0: 'Hello', 1: 'World'} │
│  var1'hello' │
│  var2'world' │
│  var313 │
│  var4 │   {'key0': 'var0', 'key1': … │
╰───────┴──────────────────────────────╯

Filtering

Additional filtering and excluding options are available as optional parameters.

  • filters may either be a list of strings and types, a list of lists or a combination of both. The outer list defines "or" filters, matching any of the elements, the inner list defines a group of "and" filters, where all elements must match. Strings are regular expressions that are matched against the variable names, the types match the variable types.
  • excl is a single list of strings and types (matched in the same way) to exclude.
>>> # Only show string variables and those whose name starts with 'var'
>>> listvars(filters=[str, '^var.*'])
╭──────┬──────┬──────┬──────────────────────────────╮
│ NameTypeSizeValue             │
├──────┼──────┼──────┼──────────────────────────────┤
│    astr34'Long string containing \n…' │
│ var1str5'hello' │
│ var2str5'world' │
│ var3int │      │                           13 │
│ var4dict2 │   {'key0': 'var0', 'key1': … │
╰──────┴──────┴──────┴──────────────────────────────╯

>>> # Only show variables that are both strings and whose names start with 'var'
>>> listvars(filters=[[str, '^var.*']])
╭──────┬──────┬──────┬─────────╮
│ NameTypeSizeValue  │
├──────┼──────┼──────┼─────────┤
│ var1str5'hello' │
│ var2str5'world' │
╰──────┴──────┴──────┴─────────╯

>>> # Same as above but also show dictionaries
>>> listvars(filters=[[str, '^var.*'], dict])
╭──────┬──────┬──────┬────────────────────────────╮
│ NameTypeSizeValue            │
├──────┼──────┼──────┼────────────────────────────┤
│ var1str5'hello' │
│ var2str5'world' │
│    ddict2 │   {0: 'Hello', 1: 'World'} │
│ var4dict2 │ {'key0': 'var0', 'key1': … │
╰──────┴──────┴──────┴────────────────────────────╯

>>> # Exlude all None types or integers (overwrites the default exclude filter!)
>>> from listvars import excl_default
>>> listvars(excl=excl_default+[type(None), int])
╭──────────────┬─────────┬───────┬──────────────────────────────╮
│     NameTypeSizeValue             │
├──────────────┼─────────┼───────┼──────────────────────────────┤
│            astr34'Long string containing \n…' │
│        arrayfloat64 │  (6,) │             min: 1, max: 3.5 │
│            ddict2 │     {0: 'Hello', 1: 'World'} │
│ excl_defaultlist │ (14,) │   [<class 'module'>, <class… │
│         var1str5'hello' │
│         var2str5'world' │
│         var4dict2 │   {'key0': 'var0', 'key1': … │
╰──────────────┴─────────┴───────┴──────────────────────────────╯

About

Python module to print a formatted list of all global variables with additional filtering options.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages