diff --git a/mylib/__init__.py b/mylib/__init__.py index 15e419e..035caa9 100644 --- a/mylib/__init__.py +++ b/mylib/__init__.py @@ -1,19 +1,25 @@ +# -*- coding: utf-8 -*- + +""" Some really common helper functions """ + # # Pretty formating helpers # def pretty_format_value(value, encoding='utf8'): + """ Returned pretty formated value to display """ if isinstance(value, dict): return pretty_format_dict(value) if isinstance(value, list): return ",".join([pretty_format_value(x) for x in value]) - elif isinstance(value, bytes): + if isinstance(value, bytes): return "'%s'" % value.decode(encoding, errors='replace') - elif isinstance(value, str): + if isinstance(value, str): return "'%s'" % value return str(value) def pretty_format_dict(attrs): + """ Returned pretty formated dict to display """ result = [] for attr in sorted(attrs.keys()): result.append(" - %s : %s" % (attr, pretty_format_value(attrs[attr]))) @@ -21,6 +27,7 @@ def pretty_format_dict(attrs): def pretty_format_list(row): + """ Returned pretty formated list to display """ result = [] for idx, values in enumerate(row): result.append(" - #%s : %s" % (idx, pretty_format_value(values)))