-
Notifications
You must be signed in to change notification settings - Fork 4
Dict rows #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Dict rows #34
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
546f773
Adding support for dictionaries as row objects. attrib will be used a…
anselor bd1b13a
Added Pipfile for use with Pipenv
tleonhardt f90a897
Should fix colors getting messed up when using the colored library. F…
anselor e3e4104
Additional customizations of the python textwrap.Textwrapper to addre…
anselor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| [[source]] | ||
| name = "pypi" | ||
| url = "https://pypi.org/simple" | ||
| verify_ssl = true | ||
|
|
||
| [packages] | ||
| wcwidth = "*" | ||
|
|
||
| [dev-packages] | ||
| tableformatter = {editable = true,path = "."} | ||
| flake8 = "*" | ||
| invoke = "*" | ||
| pytest = "*" | ||
| pytest-cov = "*" |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| #!/usr/bin/env python | ||
| # coding=utf-8 | ||
| """ | ||
| Simple demonstration of TableFormatter with a list of dicts for the table entries. | ||
| This approach requires providing the dictionary key to query | ||
| for each cell (via attrib='attrib_name'). | ||
| """ | ||
| from tableformatter import generate_table, FancyGrid, SparseGrid, Column | ||
|
|
||
|
|
||
| class MyRowObject(object): | ||
| """Simple object to demonstrate using a list of objects with TableFormatter""" | ||
| def __init__(self, field1: str, field2: str, field3: str, field4: str): | ||
| self.field1 = field1 | ||
| self.field2 = field2 | ||
| self._field3 = field3 | ||
| self.field4 = field4 | ||
|
|
||
| def get_field3(self): | ||
| """Demonstrates accessing object functions""" | ||
| return self._field3 | ||
|
|
||
| KEY1 = "Key1" | ||
| KEY2 = "Key2" | ||
| KEY3 = "Key3" | ||
| KEY4 = "Key4" | ||
|
|
||
| rows = [{KEY1:'A1', KEY2:'A2', KEY3:'A3', KEY4:'A4'}, | ||
| {KEY1:'B1', KEY2:'B2\nB2\nB2', KEY3:'B3', KEY4:'B4'}, | ||
| {KEY1:'C1', KEY2:'C2', KEY3:'C3', KEY4:'C4'}, | ||
| {KEY1:'D1', KEY2:'D2', KEY3:'D3', KEY4:'D4'}] | ||
|
|
||
|
|
||
| columns = (Column('Col1', attrib=KEY1), | ||
| Column('Col2', attrib=KEY2), | ||
| Column('Col3', attrib=KEY3), | ||
| Column('Col4', attrib=KEY4)) | ||
|
|
||
| print("Table with header, AlteratingRowGrid:") | ||
| print(generate_table(rows, columns)) | ||
|
|
||
|
|
||
| print("Table with header, transposed, AlteratingRowGrid:") | ||
| print(generate_table(rows, columns, transpose=True)) | ||
|
|
||
|
|
||
| print("Table with header, transposed, FancyGrid:") | ||
| print(generate_table(rows, columns, grid_style=FancyGrid(), transpose=True)) | ||
|
|
||
| print("Table with header, transposed, SparseGrid:") | ||
| print(generate_table(rows, columns, grid_style=SparseGrid(), transpose=True)) | ||
|
|
||
|
|
||
| columns2 = (Column('Col1', attrib=KEY3), | ||
| Column('Col2', attrib=KEY2), | ||
| Column('Col3', attrib=KEY1), | ||
| Column('Col4', attrib=KEY4)) | ||
|
|
||
|
|
||
| print("Table with header, Columns rearranged") | ||
| print(generate_table(rows, columns2)) | ||
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding unit tests related to the two things that got fixed and the new feature would be highly desirable.