Last active
August 29, 2015 13:55
-
-
Save mpkocher/8701008 to your computer and use it in GitHub Desktop.
Example of using pbreports Table and Columns
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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