Did I find the right examples for you? yes no

All Samples(6)  |  Call(3)  |  Derive(0)  |  Import(3)
Print a dictionary with keys mapping to value (or list of values).
or dictionary of values. (if dictionary, value_headers should be superset of possible keys in value dictionary)    

        def key_val_printer(key_header, value_headers):
    """Print a dictionary with keys mapping to value (or list of values).
    or dictionary of values. (if dictionary, value_headers should be superset of possible keys in value dictionary)    
    """
    
    headers = [key_header]
    
    if hasattr(value_headers, '__iter__'):
        headers.extend(value_headers)
        val_is_list = True
    else:
        headers.append(value_headers) 
        val_is_list = False
        
    def list_of_dicts_gen_singleval(d):
        """Where values of d are items"""
        return [{key_header : k, value_headers: v} for k, v in d.items()]
        
    def list_of_dicts_gen_list(d):
        """Where values of d are lists"""
        out_dcts = []
        for k, v in d.items():
            dct = dict(((vh, val) for vh, val in izip(value_headers, v)))
            dct[key_header] = k
            out_dcts.append(dct)
        return out_dcts              
    
    def list_of_dicts_gen_dict(d):
        """Where values of d are dictionaries"""
        out_dcts = []
        for k, v in d.items():
            dct = {key_header : k}
            dct.update(v)
            out_dcts.append(dct)
        return out_dcts              
        
    def helper(d, print_headers=True, kwargs={}):
        if val_is_list and isinstance(d.values()[0], dict):
            found_headers = set()
            for x in d.values():
                found_headers.update(x)
            return list_of_dicts_printer(found_headers)(list_of_dicts_gen_dict(d), print_headers)
                            
        lst_dct_gen = list_of_dicts_gen_list if val_is_list else list_of_dicts_gen_singleval
        return list_of_dicts_printer(headers)(lst_dct_gen(d), print_headers)
    
    return helper    
        


src/s/c/scicloud-3.0.4/src/cli/main.py   scicloud(Download)
 
from . import argparsers
from .util import list_of_dicts_printer, dict_printer, list_printer,\
    key_val_printer, volume_ls_printer, cloud_info_printer,\
    cloud_result_printer, cloud_result_json_printer, bucket_info_printer,\
 
    # maps the called function to another function for printing the output
    printer_mapping = {'status' : key_val_printer('jid', 'status'),
                       'info' : cloud_info_printer,
                       'result' : cloud_result_printer,

src/s/c/sciscicloud-3.0.2/src/cli/main.py   sciscicloud(Download)
 
from . import argparsers
from .util import list_of_dicts_printer, dict_printer, list_printer,\
    key_val_printer, volume_ls_printer, scicloud_info_printer,\
    scicloud_result_printer, scicloud_result_json_printer, bucket_info_printer,\
 
    # maps the called function to another function for printing the output
    printer_mapping = {'status' : key_val_printer('jid', 'status'),
                       'info' : scicloud_info_printer,
                       'result' : scicloud_result_printer,

src/c/l/cloud-2.8.5/src/cli/main.py   cloud(Download)
 
from . import argparsers
from .util import list_of_dicts_printer, dict_printer, list_printer,\
    key_val_printer, volume_ls_printer, cloud_info_printer,\
    cloud_result_printer, cloud_result_json_printer, bucket_info_printer,\
 
    # maps the called function to another function for printing the output
    printer_mapping = {'status' : key_val_printer('jid', 'status'),
                       'info' : cloud_info_printer,
                       'result' : cloud_result_printer,