Did I find the right examples for you? yes no

All Samples(15)  |  Call(12)  |  Derive(0)  |  Import(3)
Prints a list of dictionaries as a table with an optional header

        def list_of_dicts_printer(headers):
    """Prints a list of dictionaries as a table with an optional header"""
    
    def list_of_dicts_printer_helper(l, print_headers=True, kwargs={}):
        
        l = list(l)  # need to iterate twice through it
        spacing = {}
        for header in headers:
            max_column_width = len(header) if print_headers else 0
            for item in l:
                max_column_width = max(max_column_width, len(truncate(item.get(header, ''))))
            spacing[header] = max_column_width
        
        if print_headers:
            for header in headers:
                safe_print_noline( '%s%s'  % (header, ' ' * (spacing[header] - len(header) + 4)) )
            safe_print( '' )
        
        for item in l:
            for header in headers:
                safe_print_noline( '%s%s'  % (truncate(item.get(header, '')), ' ' * (spacing[header] - len(truncate(item.get(header, ''))) + 4)))
            print ''
    
    return list_of_dicts_printer_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,\
                       'rest.info' : dict_printer(['label', 'uri', 'signature', 'output_encoding', 'description']),
                       'realtime.request': dict_printer(['request_id', 'type', 'cores', 'start_time']),
                       'realtime.list': list_of_dicts_printer(['request_id', 'type', 'cores', 'start_time']),
                       'files.list': list_printer('filename'),
                       'bucket.list': list_printer('filename'),
                       'bucket.iterlist': list_printer('filename'),
                       'bucket.info': bucket_info_printer,
                       'volume.list': list_of_dicts_printer(['name', 'mnt_path', 'created', 'desc']),
                       'volume.ls': volume_ls_printer,
                       'env.list': list_of_dicts_printer(['name', 'status', 'action', 'created', 'last_modified']),
                       'volume.ls': volume_ls_printer,
                       'env.list': list_of_dicts_printer(['name', 'status', 'action', 'created', 'last_modified']),
                       'env.list-bases': list_of_dicts_printer(['name', 'distro', 'python_version']),
                       'env.get-hostname': no_newline_printer,
                       'env.get-keypath': no_newline_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,\
                       'rest.info' : dict_printer(['label', 'uri', 'signature', 'output_encoding', 'description']),
                       'realtime.request': dict_printer(['request_id', 'type', 'cores', 'start_time']),
                       'realtime.list': list_of_dicts_printer(['request_id', 'type', 'cores', 'start_time']),
                       'files.list': list_printer('filename'),
                       'bucket.list': list_printer('filename'),
                       'bucket.iterlist': list_printer('filename'),
                       'bucket.info': bucket_info_printer,
                       'volume.list': list_of_dicts_printer(['name', 'mnt_path', 'created', 'desc']),
                       'volume.ls': volume_ls_printer,
                       'env.list': list_of_dicts_printer(['name', 'status', 'action', 'created', 'last_modified']),
                       'volume.ls': volume_ls_printer,
                       'env.list': list_of_dicts_printer(['name', 'status', 'action', 'created', 'last_modified']),
                       'env.list-bases': list_of_dicts_printer(['name', 'distro', 'python_version']),
                       'env.get-hostname': no_newline_printer,
                       'env.get-keypath': no_newline_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,\
                       'rest.info' : dict_printer(['label', 'uri', 'signature', 'output_encoding', 'description']),
                       'realtime.request': dict_printer(['request_id', 'type', 'cores', 'start_time']),
                       'realtime.list': list_of_dicts_printer(['request_id', 'type', 'cores', 'start_time']),
                       'files.list': list_printer('filename'),
                       'bucket.list': list_printer('filename'),
                       'bucket.iterlist': list_printer('filename'),
                       'bucket.info': bucket_info_printer,
                       'volume.list': list_of_dicts_printer(['name', 'mnt_path', 'created', 'desc']),
                       'volume.ls': volume_ls_printer,
                       'env.list': list_of_dicts_printer(['name', 'status', 'action', 'created', 'last_modified']),
                       'volume.ls': volume_ls_printer,
                       'env.list': list_of_dicts_printer(['name', 'status', 'action', 'created', 'last_modified']),
                       'env.list-bases': list_of_dicts_printer(['name', 'distro', 'python_version']),
                       'env.get-hostname': no_newline_printer,
                       'env.get-keypath': no_newline_printer,