def dict_printer(d, order=None, header=None, output="table", sort_keys=True, show_none=""): """ TODO :param d: A a dict with dicts of the same type. :type d: dict :param order:The order in which the columns are printed. The order is specified by the key names of the dict. :type order: :param header: The Header of each of the columns :type header: list or tuple of field names :param output: type of output (table, csv, json, yaml or dict) :type output: string :param sort_keys: :type sort_keys: bool :return: """ if output == "table": if d == {}: return None else: return dict_table_printer(d, order=order, header=header, sort_keys=sort_keys) elif output == "csv": return dict_csv_printer(d, order=order, header=header, sort_keys=sort_keys) elif output == "json": return json.dumps(d, sort_keys=sort_keys, indent=4) elif output == "yaml": return yaml.dump(convert_from_unicode(d), default_flow_style=False) elif output == "dict": return d else: return "UNKOWN FORMAT. Please use table, csv, json, yaml, dict."
def dict_printer(d, order=None, header=None, output="table", sort_keys=True): if output == "table": return dict_table_printer(d, order=order, header=header, sort_keys=sort_keys) elif output == "csv": return dict_csv_printer(d, order=order, header=header, sort_keys=sort_keys) elif output == "dict": return json.dumps(d, sort_keys=sort_keys, indent=4) elif output == "yaml": return yaml.dump(convert_from_unicode(d), default_flow_style=False) else: return "UNKOWN FORMAT"
def dict_printer(d, order=None, header=None, output="table", sort_keys=True): if output == "table": return dict_table_printer(d, order=order, header=header, sort_keys=sort_keys) elif output == "csv": return dict_csv_printer(d, order=order, header=header, sort_keys=sort_keys) elif output == "dict": return json.dumps(d, sort_keys=sort_keys, indent=4) elif output == "yaml": return yaml.dump(convert_from_unicode(d), default_flow_style=False) else: return "UNKOWN FORMAT"