Skip to content

Instantly share code, notes, and snippets.

@w-vi
Last active August 29, 2015 13:58
Show Gist options
  • Save w-vi/10246073 to your computer and use it in GitHub Desktop.
Save w-vi/10246073 to your computer and use it in GitHub Desktop.
python debugging bits and pieces
#print all locals / globals but try to get rid off the builtin clutter
{k: v for k,v in locals().iteritems() if '__' not in k and 'pdb' not in k}
#something better for messy locals
def debug_nice(locals_dict, keys=[]):
globals()['types'] = __import__('types')
exclude_keys = ['copyright', 'credits', 'False',
'True', 'None', 'Ellipsis', 'quit']
exclude_valuetypes = [types.BuiltinFunctionType,
types.BuiltinMethodType,
types.ModuleType,
types.TypeType,
types.FunctionType]
return {k: v for k,v in locals_dict.iteritems() if not
(k in keys or
k in exclude_keys or
type(v) in exclude_valuetypes) and
k[0] != '_'}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment