Last active
August 29, 2015 13:58
-
-
Save w-vi/10246073 to your computer and use it in GitHub Desktop.
python debugging bits and pieces
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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