Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change code to conform to pep8 standard #257

Merged
merged 2 commits into from
Mar 29, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
change code to conform to pep8 standard
  • Loading branch information
Vinit Kumar committed Mar 29, 2016
commit eb89ffef242f5dad0e20157d3294677b5d9ecb48
72 changes: 37 additions & 35 deletions src/debug_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,39 +22,41 @@


dull_types = [str, unicode, dict, list, type(None)]


def walk_attributes(myobject, object_name, tabitem='=', step=True, tablevel=0):
"""Walk through attributes of an instance.

Just flat out prints varying values of dir() for instances and their
attributes.

Args:
myobject: instance to walk through
object_name: Name of the instance being walked through
tabitem: String to show depth into myobject. Set to '' to disable.
step: bool Use raw_input('') after printing each attribute
tablevel: Depth into myobject (starts at 0)

Returns:
NATHING!

"""
print tabitem*tablevel + 'Object: ' + object_name
print tabitem*tablevel + 'Type: ' + str(type(myobject))
attr_list = [attr for attr in dir(myobject)
if not attr.startswith('_') and
not inspect.ismethod(getattr(myobject, attr))]
print tabitem*tablevel + 'Attributes: '
print tabitem*tablevel + str(attr_list)
dull_attr = [attr for attr in attr_list
if type(getattr(myobject, attr)) in dull_types]
if dull_attr:
print tabitem*tablevel + '(basic attributes: ' + str(dull_attr) + ')'

loopable_attr = [attr for attr in attr_list
if not type(getattr(myobject, attr)) in dull_types]
for attr_name in loopable_attr:
new_object = getattr(myobject, attr_name)
if step:
raw_input('')
walk_attributes(new_object, attr_name, tablevel=tablevel+1)
"""Walk through attributes of an instance.

Just flat out prints varying values of dir() for instances and their
attributes.

Args:
myobject: instance to walk through
object_name: Name of the instance being walked through
tabitem: String to show depth into myobject. Set to '' to disable.
step: bool Use raw_input('') after printing each attribute
tablevel: Depth into myobject (starts at 0)

Returns:
NATHING!

"""
print tabitem * tablevel + 'Object: ' + object_name
print tabitem * tablevel + 'Type: ' + str(type(myobject))
attr_list = [attr for attr in dir(myobject)
if not attr.startswith('_') and
not inspect.ismethod(getattr(myobject, attr))]
print tabitem * tablevel + 'Attributes: '
print tabitem * tablevel + str(attr_list)
dull_attr = [attr for attr in attr_list
if type(getattr(myobject, attr)) in dull_types]
if dull_attr:
print tabitem * tablevel + '(basic attributes: ' + str(dull_attr) + ')'

loopable_attr = [attr for attr in attr_list
if not type(getattr(myobject, attr)) in dull_types]
for attr_name in loopable_attr:
new_object = getattr(myobject, attr_name)
if step:
raw_input('')
walk_attributes(new_object, attr_name, tablevel=tablevel + 1)
Loading