Skip to content

Instantly share code, notes, and snippets.

@mpkocher
Last active August 29, 2015 13:55
Show Gist options
  • Save mpkocher/8701008 to your computer and use it in GitHub Desktop.
Save mpkocher/8701008 to your computer and use it in GitHub Desktop.
Example of using pbreports Table and Columns
import sys
import random
from pbreports.model.model import Table, Column
def get_columns():
cs = [Column('person', header="Person Name"),
Column('color', header="Favorite Color"),
Column('pid', header='User id')]
return cs
def to_table():
cs = get_columns()
table = Table('my_table', columns=cs)
names = 'steve ralph racoon bird dog cat giraffe'.split()
colors = 'red black blue'.split()
for name in names:
table.add_data_by_column_id('person', name)
table.add_data_by_column_id('color', random.choice(colors))
table.add_data_by_column_id('pid', random.randint(0, 100))
return table
def main():
table = to_table()
print table
return 0
if __name__ == '__main__':
sys.exit(main())
[130894]mkocher@mp-f020:$ python table_example.py
Table id:my_table
--------------------------------------
Person Name Favorite Color User id
--------------------------------------
steve blue 3
ralph red 68
racoon black 72
bird red 56
dog blue 96
cat black 32
giraffe black 69
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment